const string error compilation - error C2679

Discussion in 'C Programming' started by Tassador, Jul 19, 2009.

  1. Tassador

    Tassador

    Joined:
    Jul 18, 2009
    Messages:
    3
    Location:
    Dayton, OH
    I'm currently teaching myself C++ from the book, "Learn C++ by Making Games." I'm still at the beginning of the book and have been doing all the examples as is says however; I've come across an example dealing with String Variables. I've already read about constants, variables, and literals. Keep in mind, I am using Visual C++ 2008 so I'm still learning the kinks with that as well. Here is my conflict that I am trying to understand.
    Also, since I'm still early in the book, it says to treat strings like any other variable, but make sure I declare usage of the standard namespace, as in Example 2.1 shown in Listing 2.12, or the compiler may not recognize the string type. -- I think I know what this part is talking about.

    This was the example from the book.
    /******************************
    Learn C++ by Making Games
    Example 2.1
    ******************************/

    #include <iostream>

    using namespace std;


    int main()
    {
    const string myString = "This is chapter 2.";

    cout << myString << endl;
    return 0;
    }

    When I clicked on "build," I recieved the error...error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)

    The book tells me nothing after this regarding the example.
    After messing around and looking on the net for something, I inserted #include <string> and that made it work but I have no idea why. Why didn't it work without it. Please help a newbie... Thanks!
    Tassador, Jul 19, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. c++newbie
    Replies:
    7
    Views:
    18,105
    trav580
    Feb 12, 2008
  2. aarthi28@gmail.com
    Replies:
    29
    Views:
    35,049
  3. Javier
    Replies:
    2
    Views:
    559
    James Kanze
    Sep 4, 2007
  4. hgbso

    error C2679

    hgbso, Mar 9, 2008, in forum: C Programming
    Replies:
    0
    Views:
    473
    hgbso
    Mar 9, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,798
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page