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:

Dictator Leader

Let us be clear from the outset, the struggle for indigenous people has always been about land and self-determination, not primarily about r...