> I am not sure how to use int argc, char* argv[]. Anyone could tell me when should I use it?
Whenever you need to access parameters on the command line
Your program looks OK as it stands.
> The error shows initialization of 'i' is skipped by 'default' label.
It means you have an older C++ compiler
Originally, the declaration within the for loop meant this
Code:
int i;
for( i = 1; i < argc; i++)
cout << "Argument " << i << " is " << argv[i] << endl;
The scope of i was from just before the for loop, to the end of the enclosing } (in this case, your switch statement).
Basically, you have a variable declared (i), which is not initialised in all cases.
A newer compiler declares things like so (in effect)
Code:
{ int i;
for( i = 1; i < argc; i++)
cout << "Argument " << i << " is " << argv[i] << endl;
}
Now the scope of i is much less - certainly not the whole case statment.
The GNU compiler has a switch to turn this on and off
> gxx -fno-for-scope cpr-test.cpp
cpr-test.cpp: In function `int main(int, char **)':
cpr-test.cpp:17: jump to case label
cpr-test.cpp:14: crosses initialization of `int i'
> gxx cpr-test.cpp