CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Location
    Chennai, India
    Posts
    27

    Question error C2679: binary '>>' no operator found for std::string.

    Hello friends,

    When i try this simple program in Visual C++:
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
    	string s;
    	cin>>s;
    
    	cout<<s.c_str();
    
    	return 0;
    }
    I get this error message:
    Code:
    error C2679: binary '>>' : no operator found which takes a right-hand 
    operand of type 'std::string' (or there is no acceptable conversion)
    The error message comes because of this line:
    Code:
    cin>>s;
    I dont know how to solve this problem.
    Please help me.

    Thank You,
    Paramesh.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: error C2679: binary '>>' no operator found for std::string.

    How about including <string>?
    Code:
    #include <string>
    #include <iostream>
    // the rest of your code
    If you are going to use std::string, always include <string>.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Oct 2005
    Location
    Chennai, India
    Posts
    27

    Re: error C2679: binary '>>' no operator found for std::string.

    I tried that also. But of no use.

    Any other ideas?

    PS:
    (Paul. It would be <cstring> instead of <string. Never mind)

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: error C2679: binary '>>' no operator found for std::string.

    Quote Originally Posted by cegparamesh
    I tried that also. But of no use.

    Any other ideas?

    PS:
    (Paul. It would be <cstring> instead of <string. Never mind)
    No it wouldn't. The std::string is in <string>. The <cstring> header contains the old 'C' char* functions (strcpy, strcat, etc).

    Your compiler is broken. The following compiles correctly in VC 6.0, and in any ANSI C++ compiler.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
    	string s;
    	cin>>s;
    
    	cout<<s.c_str();
    
    	return 0;
    }
    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Oct 2005
    Location
    Chennai, India
    Posts
    27

    Re: error C2679: binary '>>' no operator found for std::string.

    Thank you very much Paul.
    Sorry for my mistake.

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