Thread: Some beginner questions.

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    62

    Some beginner questions.

    I am currently trying to learn C++ from a book (Sams teach yourself C++) and I had several questions.

    Does using the following.
    Code:
    using std::cout;
    Or.
    Code:
    using namespace std;
    Instead of calling them again every time have any effect on the programs execution or is it just laziness? With calling them again every time I mean for example.
    Code:
    std::cout << "\nThis is a line of code!\n";
    Second, I see "#define" used a lot on this forum. According to my book "const" should be used instead. Why is it used so much on this forum? The book mentions that it used to be done like that but that it has been declared obsolete. Not to mention the advantages "const" has over "#define".
    Code:
    #define myAge 25
    Code:
    const unsigned short integer myAge = 25;

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    usings are just to bring in the namespace. Doesn't effect the program.

    I prefer to be explicit:
    Code:
    std::cout<<"Blah";
    const is usually the better choice. But there can be cases for the defines.
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some beginner questions.
    By Meikj in forum C++ Programming
    Replies: 3
    Last Post: 05-01-2009, 11:37 AM
  2. Total beginner questions
    By Sparky in forum C Programming
    Replies: 5
    Last Post: 06-22-2008, 04:50 AM
  3. beginner questions.
    By Jaken Veina in forum C Programming
    Replies: 5
    Last Post: 03-16-2005, 09:38 PM
  4. several beginner questions...
    By Taikon in forum C Programming
    Replies: 2
    Last Post: 02-09-2005, 09:53 AM
  5. 2 beginner questions
    By GCat in forum C++ Programming
    Replies: 15
    Last Post: 11-24-2004, 03:55 AM