Sunday

C++ main function arguments, program that knows what you type on the terminal window

Program:

#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
    cout << "Number of arguments: " << argc << endl;

    cout << "You type: ";    
    for (int c=0; c<argc; c++)
    {
        cout << argv[c] << " ";
    }
    cout << endl;

    return 0;
}

Sample run:
> g++ a.cpp
> a.exe word2 word3 word4
Number of arguments: 4
You type: a.exe word2 word3 word4

No comments:

Fire survival tips

1 Stop, drop, cover and roll  If your clothes catch fire stop, drop, cover your face with your hands and roll to smother the flames. 2 Get d...