Bogdan Maier Bogdan Maier - 1 year ago 60
C++ Question

<string> in header file

I`m trying to define a variable of string type in a class definition in a header file. Is it possible?
Example:

/* Foo.h */
#include <string>
class Foobar{
int a;
string foo;

}


Because somehow in main I can declare a string variable, but in the header it doesn’t recognize my string type.

Answer Source

string lives in namespace std. Make that:

#include <string>

class Foobar {
    int a;
    std::string foo;
};