views:

165

answers:

2

Possible Duplicate:
How to convert this code to use string

I have a function like this:

char *foo()
{

}

How can I make it return a string instead? I tried

string foo()
{

}

but the compiler complains.

+8  A: 

Did you do this:

#include <string>
using std::string;

And additionnally, do you use gcc or g++? Even if gcc now can compile C++ code, it is advised to use g++.

Benoit
I forgot the using std::string. That was the problem.
awakeFromNib
[`-1` for suggesting a using declaration.](http://stackoverflow.com/questions/2879555/c-stl-how-to-write-wrappers-for-cout-cerr-cin-and-endl/2880136#2880136)
sbi
this is not like suggesting a using namespace, heh.
Benoit
The only thing you did forget is to type "std::" in front of standard library classes/functions. Don't take the habit of "using std::string;" or "using namespace" everywhere. ( especially inside .h header files )
Nikko
+1  A: 

Try std::string. Standard features are in the std:: namespace.

std::string foo() 
{ 

} 

Be careful with "using" directives, especially in header files. Better take the habit to use std::

Nikko