accessing args via command line

Discussion in 'C++' started by mark, Jun 14, 2004.

  1. mark

    mark Guest

    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 ?
     
    mark, Jun 14, 2004
    #1
    1. Advertising

  2. mark

    Pete C. Guest

    mark wrote:
    > 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
     
    Pete C., Jun 14, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    2
    Views:
    633
    Ken Varn
    Jun 22, 2005
  2. Replies:
    3
    Views:
    495
    David Eppstein
    Sep 17, 2003
  3. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    696
    Pierre Fortin
    Sep 18, 2004
  4. er
    Replies:
    2
    Views:
    509
  5. Andrew Tomazos
    Replies:
    5
    Views:
    581
Loading...

Share This Page