假设文件 output.txt 能正常打开,下面代码通过 rdbuf 将 cout 的输出重定向到了文件中。
output.txt
rdbuf
cout
ofstream fout("output.txt"); streambuf* old_buf = cout.rdbuf(); cout.rdbuf(fout.rdbuf()); cout << "GESP Exam"; cout.rdbuf(old_buf);
正确 √
错误 ×