How do I set command line arguments for C++?

slipbits 16 Reputation points
2021-05-02T16:41:22.79+00:00

VS 16.9.4
Win7-64

Setting command line arguments in:
Debug->Debug Properties->Configuration->Debugging->Command Line Arguments

yield argc ==1, argv[0] == <path>file.exe

My command line arguments are not present. Is there any way to set up command line arguments so that during a debug session I get the arguments? I see from other posts that it is possible so I wonder what I am missing.

Developer technologies | Visual Studio | Debugging
Developer technologies | C++
{count} vote

2 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-05-02T16:48:41.363+00:00

    Before entering the arguments, select “All Configurations” and “All Platforms” in Configuration and Platform dropdown lists (or select the settings to be debugged).

    1 person found this answer helpful.

  2. RLWA32 49,536 Reputation points
    2021-05-02T20:05:46.997+00:00

    I think you have misunderstood the way command line arguments are passed. The argv array contains an entry for each command line parameter passed. Index 0 is the path to the executable. To obtain the remaining parameters you need to iterate through the array until you have referenced the number of parameters indicated by argc. Don't forget that the array indexes are zero based so the maximum valid index will be one less than the value of.argc.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.