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:

C++32 (or C++2e), C++ 2032, Cpp 2032, g++ 2032

  Subject: C++ 2032 3 Code example for ? 2 Approximate feature suggestions: - to complete C++29 or C++ 2029 1 Web links, references Wandbox,...