Reputation: 1
Whenever I try to create a string in my header file I get the error: 'string' is not a member of 'std'. I am using the Microsoft Visual c++ express 2010 compiler. Here is my header file:
using namespace std;
class Person
{
private:
string name;
string p_number;
public:
Person();
Person(string, string);
string get_number();
string get_name();
};
I am a decent java programmer who just started learning c++
Upvotes: 0
Views: 1282
Reputation: 19914
using std::string;
will not include unnecessary declarations and definitions present in string
header and will be helpful only for compiler's lookup and would compile fine, I usually prefer following instead of including whole header files:
using std::cout;
using std::cin;
using std::endl;
*For example purpose only.
Upvotes: 0
Reputation: 43619
You must include the string file like this:
#include <string>
to use std::string
.
It's something like import in Java, except that Java imports classes / namespaces, C++ imports libraries or header files.
Upvotes: 2
Reputation: 10918
Do you also have #include <string>
in your header? You need it for the declarations of the string classes.
Upvotes: 4