Solved

error message from debugger

Posted on 2011-02-17
3
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

728 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