C++错误:'string'尚未声明

neu*_*cer 14 c++ string g++ header

在我的头文件中,我得到了

错误:'string'尚未声明

错误,但在我的文件的顶部#include <string>,所以我怎么能得到这个错误?

Geo*_*che 34

string驻留在std命名空间中,您必须std::string通过使用指令或使用声明来使用或将其引入范围.


小智 5

使用

std::string var;
Run Code Online (Sandbox Code Playgroud)

要么

using namespace std;
string var;
Run Code Online (Sandbox Code Playgroud)

字符串位于std名称空间中,因此您必须让编译器知道。

  • 只要您在自己的翻译单位的隐私下进行此操作即可。 (3认同)
  • @aschepler:生我的孩子 (2认同)