페이지

2013년 2월 27일 수요일

cout 출력을 파일로 저장하기

#include 
#include 
using namespace std;

int main ()
{
   cout << "This is sent to prompt" << endl;
   ofstream file;
   file.open ("test.txt");
   streambuf* sbuf = cout.rdbuf();
   cout.rdbuf(file.rdbuf());
   cout << "This is sent to file" << endl;
   cout.rdbuf(sbuf);
   cout << "This is also sent to prompt" << endl;
   return 0;
}

댓글 없음:

댓글 쓰기