1.保存I/O流

下面这段代码cout会失效,原因是cout重定向之后失效。

#include <iostream>
#include <fstream>
using namespace std;
//using namespace boost;

int main()
{
	string filename("c:/test.txt");
	cout << "log start" <<endl;
	if (!filename.empty())
	{
		ofstream fs(filename.c_str());
		cout.rdbuf(fs.rdbuf());
		
	}
	cout << "log finish" <<endl;
	return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2021-10-29
  • 2021-07-21
  • 2021-12-30
  • 2022-01-22
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2021-12-10
  • 2021-07-18
  • 2021-05-28
  • 2022-01-07
  • 2021-07-14
相关资源
相似解决方案