繁体   English   中英

在类C ++中使用字符串会输出错误

[英]Using string in a class c++ outputs error

我想创建一个使用字符串库的C ++类。 这是我的源代码:

test.h:

#include <string>


class info {
public:
    // constructor
    info (string first_name, string last_name, int age);
    // deconstructor
    ~info ();



private:
    string first_name;
    string last_name;
    int age;

};

这是我的标题辅助文件:test.cpp

#include <string>
#include "test.h"


info::info (string first_name, string last_name, int age) {
    this->first_name = first_name;
    this->last_name = last_name;
    this->age = age;

}
info::~info () {
}

但是它给我语法错误:标识符“字符串”未定义

这是为什么? 我有点喜欢C ++数据结构

另外,我正在编译的是Visual Studio 2012

您在使用限定名称 (名称空间std的标识符)时,必须在string之前具有std::

例如,构造函数应如下所示:

info (std::string const& first_name, std::string const& last_name, int age);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM