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

dp564396 单选题 共 个子题

小杨用文件重定向实现在 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;
}
A

cout << "This output will go to the log file." << endl;

B

log_file << "This output will go to the log file." << endl;

C

cout >> "This output will go to the log file." >> endl;

D

log_file >> "This output will go to the log file." >> endl;

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧