Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't print a substring

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I was trying to print a substring on to the screen and got the error below. Any ideas?

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

The code that generated the error is as below:

#include <iostream.h>
#include <stdlib.h>
#include <string>
using namespace std;

main()
{

string state(&quot;empire&quot;);
cout <<state.substr(1,7)<< endl ;
}
 
Use <iostream> not <iostream.h>. The old iostream.h does not have support for displaying strings using cout evidently.

-bitwise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top