创建输出流,遇到报错“<error-type> out”“此声明没有存储类或类型说明符 ”
“没有与这些操作数匹配的<<运算符”
经过查询,参考文章c++ 此声明没有存储类或类型说明符_游骑兵RANGER的博客-优快云博客_c++ 此声明没有存储类或类型说明符
得知,ofstream也是一个类,其创建的实例要放在main函数里面;
#include <iostream>
#include <fstream>
std::ofstream out;
out.open("test.txt");
int main()
{
out << "fxxk" << std::endl;
return 0;
}
改成如下
#include <iostream>
#include <fstream>
int main()
{
std::ofstream out;
out.open ("test.txt");
out << "fxxk" << std::endl;
return 0;
}