I am a novice programmer learning C++ and the following question can be considered cross platform as I tried this both in Visual Studio 2010/12 and Qt Creator in Linux Mint.
I have set up the main() function of my program to accept command line arguments like this:
int main(int argc, char* argv[])
{
if(argc < 5)
{
printf("Not enough input parameters!\n");
printf("Usage:\n");
printf("'program' lamda1 lamda2 Attraction_Range Order_Param_Range\n");
return 0;
}
else
{
lamda1 = atof(argv[1]);
lamda2 = atof(argv[2]);
attRange = atof(argv[3]);
oRange = atof(argv[4]);
cout << lamda1 << lamda2 << attRange << oRange << endl;
}
}
However, when I hit Ctrl+F5
in Visual Studio or Ctrl+R
in Qt Creator, to compile, the code forks to the if
statement because I cannot input any parameters. Can I somehow pass initial arguments to my program, so that when it compiles, it can immediately go to the else
part of the above example?
I am sorry if this is a duplicate/ wrong question, but I didn't even know how to search for this on the net.