forked from markfloryan/pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdlineparams.cpp
22 lines (20 loc) · 871 Bytes
/
cmdlineparams.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// handling command-line parameters
#include <iostream>
using namespace std;
int main (int argc, char* argv[]) {
// the command-line parameters are stored as C-style strings in the
// argv[] array. argc contains 1 more than the number of command
// line parmaeters specified.
// the 0th command line parameter is always the program name.
// we can print a C-style string directly through cout:
cout << "This program is called '" << argv[0] << "'" << endl;
cout << "The following are the command line parameters you specified: " << endl;
// this for loop starts at 1 to avoid printing the name of the program
for ( int i = 1; i < argc; i++ ) {
// we can convert the C-style strings into C++-style strings:
string s(argv[i]);
// and then print them out:
cout << "\t" << s << endl;
}
return 0;
}