# 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 on other sites
Quote:
 Original post by Android07cin >> 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 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 on other sites
You need to:

#include <string>

Since string is part of the std namespace, you must use:

using namespace std;

or

std::string

##### Share on other sites
Thanks everyone, but it's working again now, I didn't have string.h included only iostream.h.

I didn't think that I needed to include both as the string type was recognised.

Thanks again.

##### Share on other sites
Quote:
 Original post by Android07Thanks 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628364
• Total Posts
2982269

• 10
• 9
• 13
• 24
• 11