Bogdan Maier Bogdan Maier - 1 year ago 92
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?

/* 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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download