[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

error message from debugger

Posted on 2011-02-17
3
Medium Priority
?
275 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.

831 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