string’ does not name a type 错误解析

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

 

示例理解:

 
 
  1. #ifndef EMP_H

  2. #define EMP_H

  3. #include

  4.  
  5. struct menuEntry

  6. {

  7. string uID; //error: 'string' does not name a type

  8. string uName; //error: 'string' does not name a type

  9. };

  10.  
  11. #endif//EMP_H

 

 
 
  1. #ifndef EMP_H

  2. #define EMP_H

  3. #include

  4.  
  5. struct menuEntry

  6. {

  7. std::string uID; /* ok */

  8. std::string uName; /* ok */

  9. };

  10.  
  11. #endif//EMP_H

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

别忘了包含头文件

你可能感兴趣的:(string’ does not name a type 错误解析)