c++ - #include <string> 在 header 中定义了一些结构。错误 : string does not define a type

标签 c++ header struct include types

#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 < string> 放在 header 保护上方时,我得到了同样的错误。想一想,我以前在将结构定义放在标题中时遇到过奇怪的麻烦。一定是我没有得到的东西。

最佳答案

您需要将string 更改为std::string,即

#ifndef STRCUTS_H
#define STRCUTS_H

#include <string>

struct menuEntry 
{ 
    std::string itemID;
    std::string itemName;
};

#endif

关于c++ - #include <string> 在 header 中定义了一些结构。错误 : string does not define a type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4931751/

相关文章:

c++ - 为什么抛出引用调用复制构造函数的异常?

javascript - 跨浏览器兼容性的脚本链接格式

python - 如何将标题行添加到 Pandas DataFrame

C++,头文件中的对象声明

c - 访问嵌套结构的元素

c++ - 增加免费商店分配的内存的方法

c++ - 使用 C++ 中的 "new"创建的指针进行内存管理

c++ - 读取文件并添加到数组 char

c - 在C中读取文件时忽略不必要的字符

c - C 标准对指向结构的指针及其第一个成员有何规定?