CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Posts
    16

    help... error with string

    hi, i am just going through accelerated cpp. Using VC, I have written the below code as a console application :

    #include <iostream.h>
    #include <string>

    using namespace std;
    int main()
    {
    string name;
    cout << "enter ur name " << endl;
    cin >> name;
    return 0;
    }


    On compilation, getting the below error for cin >> name; its exactly as the book says. What is happening here.. please help!!!

    f:\sunita\work\helloo\helloo.cpp(8) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conver

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725
    It should be :

    Code:
    #include <iostream>   // no .h
    You should you the standard headers, not the
    old-style headers from before ISO standardization.

  3. #3
    Join Date
    Jul 2001
    Posts
    16

    Thumbs up Thanks

    thanks for pointing it out to me..

  4. #4
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    ... and if the book you're using does have iostream.h in its examples, ditch it and get a book by someone who knows what he's talking about.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured