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
    Likes Received:
    0
    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. Advertisements

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,502
    trav580
    Feb 12, 2008
  2. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,559
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  3. Ook
    Replies:
    8
    Views:
    588
    Victor Bazarov
    Mar 17, 2007
  4. Jonas.Holmsten@gmail.com

    Casting int'** to 'const int * const * const' dosn't work, why?

    Jonas.Holmsten@gmail.com, Jun 1, 2007, in forum: C Programming
    Replies:
    11
    Views:
    1,383
    lawrence.jones@ugs.com
    Jul 1, 2007
  5. aarthi28@gmail.com
    Replies:
    29
    Views:
    36,664
  6. Javier
    Replies:
    2
    Views:
    874
    James Kanze
    Sep 4, 2007
  7. hgbso

    error C2679

    hgbso, Mar 9, 2008, in forum: C Programming
    Replies:
    0
    Views:
    656
    hgbso
    Mar 9, 2008
  8. veryhotsausage
    Replies:
    1
    Views:
    2,294
    veryhotsausage
    Jul 4, 2008
Loading...