5

I'm writing a program in C++ and it takes some command line arguments. The only way I know to pass command line arguments in VSC++ is to open up the properties and navigate to the command line argument field and enter them in, then run it. That's not exactly streamlined if I want to pass in different arguments each time I run it.

The other option is to just open up a command prompt in the directory where the executable is placed and to run it from the command line there, but then if I want to use the debugger I have to attach it and that's a pain too.

Is there a better way to do this?

Alex
  • 14,973
  • 13
  • 59
  • 94

3 Answers3

4

If its just for quick testing or whatever, you could just create local variables in your main method instead of passing arguments in. Makes it a lot quicker/easier to change them.

James
  • 80,725
  • 18
  • 167
  • 237
  • 5
    And for the sake of not accidentially leaving this code in a release build you can use smth like #ifdef _DEBUG to only have this code in non-release version of code. – sharptooth Jul 10 '09 at 08:04
3

I don't think there's anything built-in that can do that, but you could write a macro that asks for input, sets the command line arguments and starts the debugger. I don't have code to sets the command line arguments, but I could probably dig up some code that starts the debugger.

Regards,

Sebastiaan

Sebastiaan M
  • 5,775
  • 2
  • 27
  • 28
3

The StackOverflow link below shows how to do this, answered by grrussel:

devenv /debugexe 'program name' 'program arguments'

This way you can start the debugger from a command line.

Debugging with command-line parameters in Visual Studio

Community
  • 1
  • 1
Amadeus45
  • 1,228
  • 2
  • 17
  • 28