Solved

error message from debugger

Posted on 2011-02-17
3
266 Views
Last Modified: 2012-05-11
Hi, I am getting an error  message. I am using MS VS 2008.
The code seems correct.

here is the message I am getting:
1>c:\documents and settings\frenchmatt\my documents\visual studio 2010\projects\prj\prj\main.cpp(8): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

#include<iostream>

using namespace std;


void display(int a, int b){cout<<"hello\n";}
void display(){cout<<"I said\n";}
void display(int b, string a){cout<<a<<" "<<b<<endl;}
int main(){

	display();
	display(1,2);
	display(3,"that's all");

return 0;}

Open in new window

0
Comment
Question by:pgmerLA
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 34922800
Add this:

#include <string>

for the binary '<<'  operator
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 34924029
that was easy !!!
0
 
LVL 32

Expert Comment

by:phoffric
ID: 34924139
Yeah, it's all easy after you have been burned a hundred times - then you learn not to touch the stove! How many times did I forget to say using namespace std; and get 200 errors!! I find it odd that string compiles without #include <string>! That should not happen IMO.
But it is the <string> header that has all the overloaded operators for streaming. Here's an example of what I extracted from the VS 2010 Express <string> header:
template<class _Elem,
	class _Traits,
	class _Alloc> inline
	basic_ostream<_Elem, _Traits>& operator<<(
		basic_ostream<_Elem, _Traits>& _Ostr,
		const basic_string<_Elem, _Traits, _Alloc>& _Str) {...

Open in new window

and just one more example:
template<class _Elem,
	class _Traits,
	class _Alloc> inline
	basic_istream<_Elem, _Traits>& operator>>(
		basic_istream<_Elem, _Traits>& _Istr,
		basic_string<_Elem, _Traits, _Alloc>& _Str)
	{	// extract a string
	return (_STD move(_Istr) >> _Str);
	}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 28
returning a dereferenced pts in C++ 10 141
How to programmatically differentiate between C and Java 10 188
thread-safe code in c++ 2 84
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now