Jump to content

Newbie C++ Question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
tagavegeta

tagavegeta

    Newbie

  • Members
  • Pip
  • 1 posts
Hi guys! I'm beginning to self learn C++, I borrowed a book from the local library, "C++ for dummies". The book is very detailed, and "kind" to a newbie such as myself, but there are some lines that the book did not explain that I wish to understand. I hope you do not mind me asking. Here's the code:
// BoolTest - Compare variables from the 
//            keyboard and store the results off
//            into a logical variable
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    // set output for bool variables
    // to true and false instead
    // of 1 and 0
    cout.setf(cout.boolalpha);
    
    // initialize two arguments
    int nArg1;
    cout << "Input value: 1 ";
    cin >> nArg1;
    
    int nArg2;
    cout << "Inpute value 2 ";
    cin >> nArg2;

    bool b;
  
    b = nArg1 == nArg2;
    cout << "The statement, " << nArg1
         << " equals "         << nArg2
         << " is "             << b
         << endl;
         
    // wait until user is ready before terminating program
    // to allow the user to see the program results
    system("PAUSE");
    return 0;
}
and now, here are my questions:
1.) what's this line for? "using namespace std;"
-- the book used this line without explaining it, I'd like to find out what this is for.

2.) I've noticed that the book used this line:
int main(int nNumberofArgs, char* pszArgs[])

whereas replacing it with:
int main()

did not return any noticeable errors or change in the nature of the program when I recompiled it. What's the use of the extra string inside those parentheses?

Thanks a bunch!

Edited by WingedPanther, 26 July 2009 - 02:29 PM.
add code tags (the # button)


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
1) It allows you to use cin and cout without prefixing them with std::. It won't really make sense until you get into classes and namespaces (about 1/3 to 1/2 way into the book). It's not that important at this stage.

2) The long version allows you to read in command line arguments. If you aren't using them, it doesn't make much difference.

Also, please use code tags (the # button) when posting code.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog