identifier "string" undefined?

Solution 1:

<string.h> is the old C header. C++ provides <string>, and then it should be referred to as std::string.

Solution 2:

You want to do #include <string> instead of string.h and then the type string lives in the std namespace, so you will need to use std::string to refer to it.

Solution 3:

You forgot the namespace you're referring to. Add

using namespace std;

to avoid std::string all the time.

Solution 4:

Because string is defined in the namespace std. Replace string with std::string, or add

using std::string;

below your include lines.

It probably works in main.cpp because some other header has this using line in it (or something similar).

Solution 5:

Perhaps you wanted to #include<string>, not <string.h>. std::string also needs a namespace qualification, or an explicit using directive.