Starting out, and don't understand this

This is a discussion on Starting out, and don't understand this within the C++ Programming forums, part of the General Programming Boards category; Hey all, Im reading Sams Teach Yourself C++ in 21 Days. Its a good book so far I think. But ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    4

    Starting out, and don't understand this

    Hey all,
    Im reading Sams Teach Yourself C++ in 21 Days. Its a good book so far I think. But I think he wrote something wrong.
    I am typing in the code exactly as soon on page 18:
    Code:
    #include <iostream>
    
    int main()
    {
    std:cout << "Hello World!\n";
    int x;
    std::cin >> x;
    	return 0;
    }
    And I get the following errors:
    --------------------Configuration: Example1 - Win32 Debug--------------------
    Compiling...
    ex1.cpp
    c:\program files\microsoft visual studio\myprojects\example1\ex1.cpp(5) : error C2065: 'cout' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\example1\ex1.cpp(5) : error C2297: '<<' : illegal, right operand has type 'char [14]'
    Error executing cl.exe.

    Example1.exe - 2 error(s), 0 warning(s)


    Can anyone tell me what is wrong? I copied it exactly out of the book. Im using Microsoft Visual C++ 6.0

    If you need any other info let me know, thanks in advance to anyone that helps me out.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,954
    You have a typo, std:cout should be std::cout
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    Lol thanks I didn't see that
    Thanks

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    You can download the source code.

    First, it's a really good idea to hand-type in all of the example programs. But, you can download the source code at the author's website. I had to do this a couple of times when I couldn't see my typo.

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    ^ Agreed.
    When you run into this type of problem, though, even when your more experienced, sometimes it helps just to wipe out the problem line of code and rewrite it. It has little to do with skill. You just happen to be seeing what should be there, not what is there.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    Good book if i do say so myself, own it too hehe
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21