第23448题 单选题
C++中通过cout重定向输出日志到log.txt,横线处应填入的代码是?

小杨用文件重定向实现在 log.txt 文件中输出日志,现有代码如下,横线处应填写:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    ofstream log_file("log.txt");

    streambuf* original_cout = cout.rdbuf();
    cout.rdbuf(log_file.rdbuf());

    _________________________ // 在此处填入代码

    cout.rdbuf(original_cout); // 恢复原始的标准输出缓冲区
    return 0;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析