Daniel Porter
Daniel Porter

Reputation: 1

Errors creating a string in c++

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

Answers (5)

Rajendra Uppal
Rajendra Uppal

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

Angus
Angus

Reputation: 1350

Put

#include <string>

at the top of the file.

Upvotes: 1

mauris
mauris

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

Wyzard
Wyzard

Reputation: 34563

You need to #include <string>.

Upvotes: 1

Niall C.
Niall C.

Reputation: 10918

Do you also have #include <string> in your header? You need it for the declarations of the string classes.

Upvotes: 4

Related Questions