‘string’ does not name a type 错误解析

来源:互联网 发布:夏天乳液推荐 知乎 编辑:程序博客网 时间:2024/05/06 22:52

‘string’ does not name a type 今天写代码有一次遇见这错误!虽然不是第一次遇见了,但还是耽误了一小会,为了不再耽误时间,所以把错误写下

示例理解:

#ifndef EMP_H #define EMP_H #include <string>  struct menuEntry  {      string uID;    //error: 'string' does not name a type     string uName;  //error: 'string' does not name a type };  #endif//EMP_H

#ifndef EMP_H #define EMP_H #include <string>  struct menuEntry  {      std::string uID;      /* ok */           std::string uName;    /* ok */ };  #endif//EMP_H

也可以直接加上命名空间using namespace std;

别忘了包含头文件<string>

原创粉丝点击