Thread: Why doesn't this compile? Sample code from book 2.2!!! And it doesn't compile

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Why doesn't this compile? Sample code from book 2.2!!! And it doesn't compile

    Code:
    // Listing 2.2 using std::cout
    #include <iostream>
    int main()
    {
    	std::cout << "Hello there.\n";
    	std::cout << "Here is 5: " << 5 << "\n";
    	std::cout << "The manipulator std::endl ";
    	std::cout << writes a new line to the screen.";
    	std::cout <<  std::endl;
    	std::cout << "Here is a very big number:\t" << 70000;
    	std::cout << std::endl;
    	std::cout << "Here is the sum of 8 and 5:\t";
    	std::cout << 8+5 << std::endl;
    	std::cout << "Here's a fraction:\t\t";
    	std::cout << (float) 5/8 << std::endl;
    	std::cout << "And a very very big number:\t";
    	std::cout << (double) 7000 * 7000 << std::endl;
    	std::cout << "Don't forget to replace Jesse Liberty";
    	std::cout << "with your name...\n";
    	std::cout << "Jesse Liberty is a C++ programmer!\n";
    	return 0;
    }
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Code:
    std::cout << writes a new line to the screen.";
    should be
    Code:
    std::cout << "writes a new line to the screen.";
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Thank you.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    There's nothing wrong with having std::endl inside a string. It's not intended to be executed. It's just there to print as part of the string:
    "The manipulator std::endl writes a new line to the screen."

    The only error was the omission of the " at the beginning of the 4th cout statement.

Popular pages Recent additions subscribe to a feed