Microsoft Specific
Microsoft C/C++ startup code uses the following rules when interpreting arguments given on the operating system command line:
argv
array in the program.argv
array for every pair of backslashes, and the double quotation mark is interpreted as a string delimiter.argv
array for every pair of backslashes, and the double quotation mark is “escaped” by the remaining backslash, causing a literal double quotation mark (") to be placed in argv
.The following program demonstrates how command-line arguments are passed:
include <iostream.h>
void main( int argc, // Number of strings in array argv
char *argv[], // Array of command-line argument strings
char *envp[] ) // Array of environment variable strings
{
int count;
// Display each command-line argument.
cout << "\nCommand-line arguments:\n";
for( count = 0; count < argc; count++ )
cout << " argv[" << count << "] "
<< argv[count] << "\n";
}
Table 2.2 shows example input and expected output, demonstrating the rules in the preceding list.
Command-Line Input | argv[1] | argv[2] | argv[3] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
END Microsoft Specific