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.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,970 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,098 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Viorel 122.3K 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,426 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.