3.14 COMMAND LINE ARGUMENTS

These days we run our programs from integrated development environments like TurboC++. They offer us various services. However, when we have a program in machine language form (.exe) file, we execute it from command line of our operating system (DOS, Windows, Linux, etc.) At that time, we can pass parameters to our programs. These parameters are termed as command line arguments. The C++ language has reserved keywords argc and argv for use in this situation. Variable argc stores the number of arguments passed. Variable argv is an array of strings. It stores the arguments as a string. Suppose we have a program cla1.exe, we can run it as:

Command Prompt> cla1 good morning <enter>

In this case, “good” and “morning” are ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.