C++ 错误:“字符串”尚未声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2890860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ error: ‘string’ has not been declared
提问by neuromancer
In my header file I'm getting the
在我的头文件中,我得到了
error: ‘string' has not been declared
错误:“字符串”尚未声明
error but at the top of the file I have #include <string>
, so how can I be getting this error?
错误但在我的文件顶部#include <string>
,那么我怎么会收到这个错误呢?
回答by Georg Fritzsche
string
resides in the std
namespace, you have to use std::string
or introduce it into the scope via using directives or using declarations.
string
驻留在std
命名空间中,您必须std::string
通过 using 指令或 using 声明使用或将其引入范围。
回答by KamikazeCZ
Use
用
std::string var;
or
或者
using namespace std;
string var;
String is in a stdnamespace so you must let your compiler know.
字符串位于std命名空间中,因此您必须让编译器知道。