Working on an assignment for a class, been going in circles on how to get arguments from the command line and pump them through a rot13. My rot13 works perfectly if a user just types in the text, but I cannot figure out how to pull the arguments in. For example if my arguments are: Glory to Rome!
Command line arguments are passed via the command line, not read with cin.
./yourProgramName 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main(int argc, char **argv)
{
// argc is the number of parameters passed from the command line.
cout << "Number of arguments: " << argc << endl;
for(int i = 0; i < argc; ++i)
cout << "Argument " << i << " is " << argv[i] << endl;
if(argv[argc] == nullptr) // If not using a C++11 compiler replace nullptr with 0.
cout << "argv[" << argc << "] is equal to a nullptr" << std::endl;
return 0;
}