开发者

Errors creating a string in c++

开发者 https://www.devze.com 2023-01-27 07:14 出处:网络
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:

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 开发者_如何学Cstarted learning c++


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


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.


You need to #include <string>.


Put

#include <string>

at the top of the file.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号