-1

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
Dima1982
  • 189
  • 3
  • 18
  • Why would you want to do that? You might as well not pass them at all, if you're going to do it at compile time. – mwerschy May 26 '13 at 18:43
  • 1
    Qt is a framework. Qt Creator is an IDE. Neither of those is a compiler. Your question is not cross-platform at all. You're asking the same a question for two different IDEs. That's not a good idea. – Mat May 26 '13 at 18:45
  • @mwerschy: Yes, that is true. I just thought it would save some time, since now I have to navigate to the generated executable and type the command in `powershell/ bash`. @Mat: You are correct of course. The terminology still eludes me... – Dima1982 May 26 '13 at 18:46
  • Then you still want run-time, you just want the IDE to do it for you. @Riateche has the correct answer then. – mwerschy May 26 '13 at 18:49

1 Answers1

4

In Visual Studio: How could I run a project with some parameters in Visual Studio?

In Qt Creator: QtCreator and Command Line Arguments

Community
  • 1
  • 1
Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127