Tutorial2

Adapted from Stephen J. Chenney's Tutorial
Modified by Yu-Chi Lai in 2005
Modified by Yoh in 2007 (updated for VS05)

1.  Step 1: What Are Command Line Arguments?

In the past DOS, we need to type in the command for executing the program instead of clicking the icon in the window system. We also need to parse in the parameters needed for the command to execute the program in the user's desired way. In window, the GUI will be used to communicate with the user. In DOS, command line arguments are used to parse in users' specified parameters. In the following figure, "C559 Tutorial 2.exe" is the command and So long and thanks for all the fish are the command line arguments being parsed in.

 
 

2.  Step 2: Modify Main

 
 
#include <iostream>
using namespace std;
int main(int argc, char** args)
{
	// Notice I start from i=1 not 0 because the args[0] is reserved 
    //        for the name of this program.
	for(int i = 1; i < argc; i++)
	{
	     cerr << i << "th argument is " << args[i] << "\n";
	}
}

This new version of main go through the command argument and then print all of them on the console.

 

3.  Step 3: Modify Project's Command Arguments Setting

 
 
 
 

4.  Step 4: Build Project

 

5.  Step 5: Run the Program

To run our program from within the VS05 enviroment we simply choose Debug -> Start Without Debugging. You should see this console window appear. Congratulations! You've got your first successfullVS05 project.

 

Source Code