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:
I dont know how to solve this problem.
Please help me.
Thank You,
Paramesh.
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
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)
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
Re: error C2679: binary '>>' no operator found for std::string.
Thank you very much Paul.
Sorry for my mistake. :D