Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String problem?

Status
Not open for further replies.

Monster123

IS-IT--Management
Jun 2, 2004
2
0
0
DE
I came across this error when I do my assignment...

it's a cout with a string... don't know why it happens to all cout/cin line....

c:\new folder\peg.cpp(58) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
Error executing cl.exe.

pls give me a hand
 
I ran across the same problem yesterday. Turns out that it's most likely due to putting #include <iostream.h> instead of just #include <iostream> (no .h). Try that and do post your code so I can make sure this is what you're referring to.
 
i think that ur gonna have to overload the operator &quot;<<&quot; in yor sting class. the is no definition in iostream for &quot;<<&quot; of a string.
 
jonny b, try this out:

#include <iostream>
#include <string>
using namespace std;

void main()
{
double age;
string name;

cout << &quot;how old are you?&quot;;
cin >> age;
cout << &quot;what is your name?&quot;;
getline(cin, name);
getline(cin, name); //two needed to take in the \n character left over from the cin >> age
}

it will take in your age and your name including spaces. using <iostream.h> will not allow you to do this.
 
thanks i got it!

it's the !@#$%^& .h

many thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top