accessing args via command line

M

mark

int main(int argc, char *argv[])

Not giving the argument via command line and trying to access it
inside the
program, gives the following error

on VC++ Application error (launches debugger if requested)
on Linux g++ "PWD=/home/local" (the present working directory where
the
program was called from

on VC++ it is fine as one is trying to access a memory location which
has not been defined.
How is g++ handling this error ? is it ok ?
 
P

Pete C.

mark said:
int main(int argc, char *argv[])

Not giving the argument via command line and trying to access it
inside the
program, gives the following error

on VC++ Application error (launches debugger if requested)
on Linux g++ "PWD=/home/local" (the present working directory where
the
program was called from

on VC++ it is fine as one is trying to access a memory location which
has not been defined.
How is g++ handling this error ? is it ok ?

Just only access arguments from 0 to argc - 1:

#include <iostream>
int main(int argc, char* argv[])
{
for(int i = 0; i < argc; ++i)
std::cout << argv << std::endl;
return 0;
}

- Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top