![]() |
Command-line arguments are the values or parameters that are passed after the name of the program through the command line or terminal when the program is executed. In this article, we will learn how to retrieve command-line arguments in C++. Retrieving Command Line Arguments in C++To access all the command line arguments that are passed from the command line when the program gets executed we can use the main function’s parameters i.e. (int argc, char *argv[]) that are passed in the main function definition. Here,
We can use a loop, such as a for loop, to iterate over the argument vector that continues until the loop variable is less than argc. During each iteration, print each argument value using the array notation – argv[index] to the console to display all command-line arguments passed to the program. C++ Program to Retrieve Command Line ArgumentsThe below example demonstrates how we can retrieve command line arguments in C++.
./myProgram C++ is Programming Language Output Number of arguments: 5 |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |