【问题标题】:#include <string> in a header the defines some structs. ERROR: string does not define a type#include <string> 在标题中定义了一些结构。错误:字符串未定义类型
【发布时间】:2011-06-23 08:05:38
【问题描述】:
#ifndef STRCUTS_H
#define STRCUTS_H
#include <string>

struct menuEntry 
{ 
    string itemID;    //'string' does not name a type
    string itemName;  //'string' does not name a type
};

#endif

当我将#include 放在标头保护上方时,我得到了同样的错误。想想看,我之前在标题中放置结构定义时遇到了奇怪的麻烦。一定是我没有得到的东西。

【问题讨论】:

    标签: c++ header struct include types


    【解决方案1】:

    你需要将string改为std::string,即

    #ifndef STRCUTS_H
    #define STRCUTS_H
    
    #include <string>
    
    struct menuEntry 
    { 
        std::string itemID;
        std::string itemName;
    };
    
    #endif
    

    【讨论】:

    • 或添加using std::stringusing namespace std。仅供参考。
    • @KitsuneYMG:不——你不应该把using namespace std(或using namespace &lt;anything&gt;放在标题中。
    猜你喜欢
    • 2013-04-07
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 2021-09-14
    • 1970-01-01
    • 2020-11-14
    • 2016-05-03
    相关资源
    最近更新 更多