提问人:sweet_sugar 提问时间:11/29/2022 最后编辑:sweet_sugar 更新时间:11/29/2022 访问量:36
自 clang15 和 gcc12 以来,尝试使用 ios::eof 设置的流时,Ofstream 写入停止设置 ios::fail
Ofstream write stopped set ios::fail while trying to write to stream with ios::eof set since clang15 and gcc12
问:
请考虑以下代码:
#include <iostream>
#include <ostream>
#include <fstream>
int main() {
std::ofstream f("tmp");
f.setstate(std::ios_base::eofbit);
f.write("hello", 5);
if (f.fail())
std::cout << "write failed\n";
std::cout << "end\n";
return 0;
}
在这种情况下,在 clang15 和 gcc13 之前设置了 ios::fail 标志。为什么这种行为发生了变化?
答: 暂无答案
评论