我想这样做:
#include <string>
class Medicine{
string name;
};
Run Code Online (Sandbox Code Playgroud)
但它根本不起作用.我尝试右键单击项目 - >索引 - >搜索未解决的包含,它说:未解决包含在项目中(0匹配).它也不能用于std :: string.我该怎么办?
您应该完全符合string它所属的命名空间(std):
#include <string>
class Medicine {
std::string name;
// ^^^^^
};
Run Code Online (Sandbox Code Playgroud)
或使用using声明:
#include <string>
using std::string; // <== This will allow you to use "string" as an
// unqualified name (resolving to "std::string")
class Medicine {
string name;
// ^^^^^^
// No need to fully qualify the name thanks to the using declaration
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11979 次 |
| 最近记录: |