Solved

error message from debugger

Posted on 2011-02-17
3
263 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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

17 Experts available now in Live!

Get 1:1 Help Now