Thread: Need help compiling hello world

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    49

    Need help compiling hello world

    Hi, I am trying to learn c++ from a book called c++ primer. I am using vs .net 7.1
    This will sound like a silly question but has c++ changed heaps in this compiler?
    When i start a new win32 console app this is what it looks like

    #include "stdafx.h"

    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }


    _tmain?? whats that?

    Any way, i tried putting this line above return

    cout<<"hello world";

    and i get this error

    error C2065: 'cout' : undeclared identifier

    Is my book way out of date or are there only minor changes or is it something else?

    Thanks heaps for any info

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    You need to include the header file that defines cout. This can be done as follows:
    Code:
    #include <iostream> //Added line
    #include "stdafx.h"
    
    using namespace std; //Added line
    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }
    '#include <iostream>' tells the compiler to include that header file, and 'using namespace std' is needed so you dont have to type in 'std::' before every 'cout','cin', etc.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>_tmain?? whats that?<<

    It's a macro #defined in tchar.h as either main or wmain (wmain is the wide char or unicode version of the function).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    49
    Thanks guys, I had #include <iostream> in a header file.
    I didn't know about std::
    Is that new?
    I thought namespaces were just a part of managed code like c#
    Is there any books about c++ using vs .net?
    Thanks again

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Is that new?
    Yes, it's part of the new standard that includes the new headers (iostream, cstring etc)

    Is there any books about c++ using vs .net?
    I'm sure there are plenty, but I dont know which ones are the best. Remember that C++ .NET is fairly similar to C++ 6.0, in fact, you can program perfectly in VS .NET using only C++ 6.0 code. Check out Jesse Liberty's C++ tutorial.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    C++ primer is not the easiest of books to start learning C++ with. Also I don't think .net is the easiest program.

    If I were you I'd download a copy of Dev-C++ by bloodshed and start with that. As for books, pick something user friendly to start with. Sams Teach yourself c++ in 21 days is easy to follow. (don't expect to be a c++ programmer in 21 days though )
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  7. #7
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    I personally learned through a book entitled "The Complete Idiot's Guide to C++". It assumes you don't know how to program at all (whereas some books I've found expect you know C which at the time I didn't).

  8. #8
    Registered User Russell's Avatar
    Join Date
    May 2004
    Posts
    71
    I believe the best method is to learn standard C++ and then move on to platform specifics. Otherwise, you're going to get confused and ultimately write nonstandard code.

  9. #9
    Registered User New001's Avatar
    Join Date
    May 2004
    Posts
    6
    I'm learning with a book called C++ For the Absolute Begginer, It is a great book if you have no previous programing knowledge (And Im using DevC++).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. The 7 New Wonders of the World
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 12-08-2006, 01:55 PM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  5. Too much to ask ?
    By deflamol in forum C Programming
    Replies: 2
    Last Post: 05-06-2004, 04:30 PM