Sign in to follow this  
Android07

Simple c++ question

Recommended Posts

I'm having a problem using cin. The code used to work perfectly but know it doesn't. string name; cout << "Please enter name: "; cin >> name; When compiling I get error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) This error started when I tried to overload the << operator to use one of my own classes with cout but I didn't touch this piece of code and have now commented this out in case it would cause any problems but it still doesn't work. I am including iostream and have using namespace std;

Share this post


Link to post
Share on other sites
Quote:
Original post by Android07
cin >> name;

error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

You didn't introduce your own variable called "cin" by any chance?

Share this post


Link to post
Share on other sites
The following works. Check your includes.
#include <string>
#include <iostream>
#include <istream>
#include <ostream>

int main()
{
std::string name;
std::cout << "Please enter name: ";
std::cin >> name;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Android07
Thanks everyone, but it's working again now, I didn't have string.h included only iostream.h.
These headers have been replaced by the standard headers <string> and <iostream> in 1998. (Yes, that's 10 years ago) You should consider moving on to the current versions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this