I normally use 'getopt' for command line argument handling in Linux but sadly i come to know just now that it does not work in Visual Studio. Since this is my first time coding visual C++ 2010 code so i am having trouble parsing command line arguments. Pls see code below:
#include "StdAfx.h"
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
std::string cfgFilePath = "";
if(argc < 2)
{
std::cout<<"Usage: ApplicationName ConfigFile\n";
exit(0);
}
//cfgFilePath = argv[1]; //<<--- Ideally i want to do this. But it doesnt work
printf("\nEntered String: %s.", argv[1]);
return 0;
}
When i run its exe like "app.exe abcd" then the output i get is "Entered String: a.". Why is this happening and what i can do to correct things.
Also what can i do to make commented out line to work. Here i am getting error
"*error C2679: binary '=' : no operator found which takes a right-hand operand of type '_TCHAR ' (or there is no acceptable conversion)"
Thanks