메뉴 건너뛰기

OBG

Programming

C/C++
2013.07.28 02:44

Simplified Logger Class

MoA
조회 수 414 추천 수 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. GetLastInputInfo 함수

  3. WaitForSingleObject와의 삽질..

  4. [액션게임 만들기] 9. 캐릭터 액션 구현 2

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

  6. Simple Add-On Wait Dialog in MFC

  7. CFormView

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

  9. Visual Studio Debug Tips

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

  11. 후킹 링크

  12. Simplified Logger Class

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

  14. Great summary cheat sheet (OpenCV)

  15. Embedding Python in C/C++

  16. Redmine 설치

  17. Buffer Overrun

  18. CString class

  19. RAND_MAX

  20. 구글 검색 알고리즘의 원리

  21. Which Font is the default for MFC Dialog Controls

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