?
Solved

error message from debugger

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

650 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