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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:24:47  来源:igfitidea点击:

C++ error: ‘string’ has not been declared

c++stringheaderg++

提问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

stringresides in the stdnamespace, you have to use std::stringor 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命名空间中,因此您必须让编译器知道。