Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make function return string in c++ [duplicate]

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.

like image 719
node ninja Avatar asked Nov 29 '22 04:11

node ninja


2 Answers

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++.

like image 106
Benoit Avatar answered Dec 05 '22 02:12

Benoit


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::

like image 41
Nikko Avatar answered Dec 05 '22 01:12

Nikko