-
November 26th, 2005, 08:02 PM
#1
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.
-
November 26th, 2005, 08:48 PM
#2
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
-
November 26th, 2005, 09:01 PM
#3
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)
-
November 26th, 2005, 09:05 PM
#4
Re: error C2679: binary '>>' no operator found for std::string.
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
-
November 26th, 2005, 09:37 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|