C++ 报错 error: ‘xxx’ was not declared in this scope

2023-05-16

笔者在做C++文件的输入输出实验的时候,编译时遇到这样一个问题:

 error: ‘ofstream’ was not declared in this scope

经过检查,自己在文件头已经包含了头文件:

#include <iostream> 
#include <fstream> 

但是依旧报错,经过检查各种问题都没能找到问题所在。

后来重新对比例程并编译,发现
例程中使用了

using namespace std; 

而自己考虑到要少用 using namespace xxx; 就没有在程序使用using namespace std;,但是由于自己对 文件的输入输出操作不是很熟悉,就忘记了在 ofstream ofs("a.txt"); 前加上 std::,最终导致出现这样的报错。实在是太不应该了。
最终修改为 std::ofstream ofs("a.txt");,再次编译,编译成功。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++ 报错 error: ‘xxx’ was not declared in this scope 的相关文章

随机推荐