Thread: Starting out, and don't understand this

  1. #1
    Registered User
    Join Date
    Nov 2004

    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:
    #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--------------------
    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
    You have a typo, std:cout should be std::cout
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001

    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
    ^ 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
    Join Date
    Oct 2004
    Good book if i do say so myself, own it too hehe
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

Popular pages Recent additions subscribe to a feed