Printing a std::string

Dec 4, 2010 at 2:17pm
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....
Dec 4, 2010 at 3:41pm
hi

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

 
#include <string> 
Dec 4, 2010 at 5:01pm
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...
Dec 4, 2010 at 10:14pm
What compiler are you using?
Dec 5, 2010 at 1:09am
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 Dec 5, 2010 at 1:12am
Dec 6, 2010 at 9:49pm
In that case, wouldn't he just get an undeclared identifier error?
Topic archived. No new replies allowed.