ch3-CommandLineArgs (Print as strings)

Chapter_3     Exercise_3-21 ArgsToInts     Exercise_3-22







CommandLineArgs.cpp     TCP1, p. 201         download


#include <iostream>
using std::cout;
using std::endl;

int main(int argc, char* argv[])
{
cout << "argc = " << argc << endl;

for(int i = 0; i < argc; i++)
{cout << "argv[" << i << "] = " << argv[i] << endl;}

return 0;
}
/*
g++ CommandLineArgs.cpp -o CommandLineArgs
./CommandLineArgs
argc = 1
argv[0] = ./CommandLineArgs

./CommandLineArgs Hello!
argc = 2
argv[0] = ./CommandLineArgs
argv[1] = Hello!

./CommandLineArgs How are you?
argc = 4
argv[0] = ./CommandLineArgs
argv[1] = How
argv[2] = are
argv[3] = you?
*/









Chapter_3     Exercise_3-21 BACK_TO_TOP ArgsToInts     Exercise_3-22



Comments

Popular posts from this blog

Contents