beginner C++ discrepancy

Discussion in 'Mac Programming' started by ifjake, Nov 1, 2006.

  1. ifjake macrumors 6502a

    Jan 19, 2004
    I'm currently taking a beginners C++ course that apparently uses outdated standards and such, and I'm trying to reconcile the ways of doing things as we are taught in class with the more up-to-date ways of doing things. Previously I figured out how the .h-ending header files were different than the non-.h ones and how for example with iostream you have to add a using namespace std; line for cout statements to look normal. I'm still figuring out what that means exactly, but I can get it to work so I'm not that concerned.

    What I'm curious about now is the arguments within the main function header as put there by default when starting a C++ command line project: main(int argc, char * const argv[]). What the heck are these for? What "topic" would I look under to figure out more about this?
  2. coconn06 macrumors regular

    Jun 14, 2003
    King of Prussia, PA
    The parameters in the main() function represent values passed to your program from the command line. It's been a long time since I did C++ so bear with me; I think "int argc" is the number of arguments, and the char array is an array of the command line values.
  3. rtharper macrumors regular


    Sep 6, 2006
    Oxford, UK
    argc is the number of arguments. argv is a array of pointers to strings (i.e. an array of char arrays), each of which is one argument. Not saying you were wrong, just clarifying for the person that was asking =)
  4. cbougher macrumors member

    Oct 19, 2006
    Atlanta, GA
    Also bear in mind that the first entry in argv (offset=0) is the name of the program itself so if you call you program like this:

    >cppprogram arg1 15 2.67

    argc will be 4 and argv[] will be {"cppprogram", "arg1", "15", "2.67"}

Share This Page