在c++类中使用string会输出错误
Using string in a class c++ outputs error
我想创建一个使用string库的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 () {
}
然而,它给了我语法错误:标识符"string"是未定义的
为什么?我是c++数据结构的新手
同时,我正在编译这是Visual Studio 2012
您需要在string
之前有std::
,因为您正在使用限定名称(命名空间std
中的标识符)。
info (std::string const& first_name, std::string const& last_name, int age);
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 为什么 string::begin() 在即时窗口中输出整个字符串
- 如何将地图<列表<string>、矢量<string>>输出到输出文件?
- 自定义堆栈上 std::string 数据的输出
- 如何使用 rapidjson 读取 json 文件并输出到 std::string?
- 哈希输出为 BYTE 而不是 std::string
- swig perl typemap(out) std::vector<std::string> 在 perl 中不返回所需的输出
- std::string::append(std::string)错误输出
- 使用 std::ostream 方法将格式化文本输出到 std::string 对象
- 如何将 std::string 用于 char* 输出参数
- [swig-JavaScript]是否支持std::vector<std::string>*作为输出?
- 当传入具有std::string成员的结构时,C++-gdb会给出意外的输出
- boost::filesystem::path::string()输出的奇怪行为
- 在布尔矩阵中查找唯一的行(帮助解析std::string的垃圾输出)
- 输出流转换为String或std::ostream
- 在c++类中使用string会输出错误
- Cout在声明一个std::string变量后不给出任何输出
- 如何将<string>具有一定数量单词的向量输出读取到一行?
- 如何分配谷歌协议缓冲区SerializeAsString()输出,其中包含嵌入空到std::string