메뉴 건너뛰기

OBG

Programming

C/C++
2013.07.28 02:44

Simplified Logger Class

MoA
조회 수 435 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
#include <iostream>
#include <fstream>

using namespace std;

class Logger
{
 public:
   Logger(const char* filename = "program.log")
     {
       logfile = new fstream(filename, fstream::out);
     }
   ~Logger()
     {
       logfile->close();
       delete logfile;
     }

   Logger& operator<<(const char* msg)
     {
       *logfile << msg;
       return *this;
     }
   Logger& operator<<(const int val)
     {
       *logfile << val;
       return *this;
     }
 private:
   fstream* logfile;
};

class MyClass
{
 public:
   MyClass(const int n)
     {
       data = n;
     }

   ~MyClass()
     {
     }

   friend ostream& operator<<(ostream& o, const MyClass& v)
     {
       return o << "MyClass data = " << v.data << "n";
     }

 private:
   int data;
};

int main()
{
   Logger mainlog;
   MyClass a(10);

   // These work fine
   cout << a;
   mainlog << "Bla " << 200 << "n";

   // This doesn't work
   //mainlog << a;

   return 0;
}



?

  1. Programming 게시판 관련

  2. Google의 C++ 라이브러리

  3. GetLastInputInfo 함수

  4. Simple Add-On Wait Dialog in MFC

  5. Simplified Logger Class

  6. WaitForSingleObject와의 삽질..

  7. [첫게임 만들기] 8. Win or Lose

  8. 후킹 링크

  9. CFormView

  10. C Runtime 환경의 메모리 릭 잡는 방법 (Memory leak)

  11. 스레드 강좌 + CreateThread() 와 _beginthreadex() 함수의 차이

  12. Redmine 설치

  13. Visual Studio Debug Tips

  14. Great summary cheat sheet (OpenCV)

  15. Buffer Overrun

  16. [첫게임 만들기] 5. 적을 생성하자

  17. Quake 3 source code and review

  18. RAND_MAX

  19. Embedding Python in C/C++

  20. CString class

  21. 안드로이드 어플 개발 사이트

Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 15 Next
/ 15
위로