Printing a std::string

Hello...

I wrote a c++ program in which I received a std::string type variable. The initialization is as:

std::string *items = new string[count];


I am not able to get the output of the string with:

cout<< item[i];

Is there any other method to print such type of a sting?

Thanks....
hi

if you need to use cout with string you will need to include the string header

 
#include <string> 
Thanks for the reply...

I already included the header file. I receive this error:

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

thanks...
What compiler are you using?
Your code:
cout<< item[i];
is wrong. The problem is at namespace. In order to solve this problem, you can write like this
std::cout<< item[i];
, or you can declare namespace at this program begin with using
std::cout;
Last edited on
In that case, wouldn't he just get an undeclared identifier error?
Topic archived. No new replies allowed.