c++ - 字符串变量 'was not declared' header C++

标签 c++

<分区>

为什么 eclipse 说“名称”未在此范围内声明?上面一个是我的header,另一个是我的.ccp

#include<string>
class Characters {
public:
std::string characters(int);
std::string name;
};



string characters(int x){

ofstream characters;
characters.open("characters.txt");
while (characters >> name){
return name;
}
}

最佳答案

原因是你没有提到,这是一个类方法的实现,所以你需要像下面这样指定它:

改变:

string characters(int x)

到:

string Characters::characters(int x)

关于c++ - 字符串变量 'was not declared' header C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36645928/

相关文章:

c++ - 如何通过 win32 c++ 应用程序打开网页

c++ - 在指针场景中使用 std::shared_ptr

c++ - C++ 中的 SDL 静音音量

c++ - Javascript 的 "in"的 C++ 等价物是什么?

c++ - 如何打印数组的内容而不在堆栈上创建任何内容?

c++ - 通过一个 switch 语句发送不同的变量

c++ - 将默认构造的迭代器与 operator== 进行比较

c++ - 你如何在 C++ 中的 priority_queue 中排序对象?

c++ - MRPT Graph Slam 最小示例

c++ - push_back on 2D std::vector< std::vector<char*>> value made all the values are the same