‹ 上一题 下一题 ›

g4-03937. GESP-4级-2024-09-单选-第14题 未做

小杨用文件重定向实现在 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;
未选择
输入
输出

            
答案