I am doing an assignment for a class and noticed I may need argc and argv, but when I look it up to learn about it I keep seeing mentions of a command line, but have no clue how to input arguments from a command line. I just needed help figuring out where to input in the command line as the websites I visited never showed where exactly the command line was. I understood how it worked. The coding environment I was using was Visual Studio 2017.
Asked
Active
Viewed 214 times
-12
-
3If you are actually on the command line you type them in after the name of the executable (probably separated using spaces between arguments). If you are on some IDE it will have a place to enter command line arguments. In Visual Studio it is in the Debugging options for your executable target. – drescherjm Feb 05 '18 at 17:47
-
1Probably if you are using an IDE (XCode or something like that) to compile and run your program, in the compilations / run options you can set the `command line` options to be passed to your program. – Fredster Feb 05 '18 at 17:48
-
Note that calling them "command line" arguments reflects the traditional way in which they are specified to the program, but the standard does not use that terminology, and does not specify from whence the environment gets values for those parameters. – John Bollinger Feb 05 '18 at 17:59
-
Doing Nihat’s homework last minute huh? (; – Feb 05 '18 at 18:03
-
1I think the OP is asking something more fundamental: what's a command line? I suspect you're using either Windows or a Mac, and you've never brought up Mac Terminal or Windows cmd.exe. You should do that, and learn how to use them. – Lee Daniel Crocker Feb 05 '18 at 18:19
1 Answers
1
Here is an example program that shows how to access command line parameters:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
cout << "You have entered " << argc << " arguments:" << "\n";
for (int i = 0; i < argc; ++i) {
cout << argv[i] << "\n";
}
return 0;
}
If you run this from the command line like this:
./myprogram hello world
You would see the following output:
You have entered 3 arguments:
./myprogram
hello
world
If you are running your program from a specific IDE then you will need to look up the specific instructions for your IDE on how to pass parameters to your application.

Jeff Melton
- 357
- 4
- 13