Why I cannot cout a string?

Ata picture Ata · Jun 12, 2011 · Viewed 228.3k times · Source

Why I cannot cout string like this:

string text ;
text = WordList[i].substr(0,20) ;
cout << "String is  : " << text << endl ;

When I do this, I get the following error:

Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\users\mollasadra\documents\visual studio 2008\projects\barnamec\barnamec\barnamec.cpp 67 barnamec**

It is amazing, that even this is not working:

string text ;
text = "hello"  ;
cout << "String is  : " << text << endl ;

Answer

Kiril Kirov picture Kiril Kirov · Jun 12, 2011

You need to include

#include <string>
#include <iostream>