메뉴 건너뛰기

OBG

Programming

C/C++
2013.07.28 02:44

Simplified Logger Class

MoA
조회 수 439 추천 수 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. DoModal Dialog 기초

  3. InvalidateRect 함수, flag성 메세지

  4. CreateThread, ExitThread, GetExitCodeThread ...

  5. CSpreadSheet

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

  7. CSS, 자바스크립트 강좌

  8. Which Font is the default for MFC Dialog Controls

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

  10. RAND_MAX

  11. Quake 3 source code and review

  12. CString class

  13. Embedding Python in C/C++

  14. Buffer Overrun

  15. Great summary cheat sheet (OpenCV)

  16. Redmine 설치

  17. Visual Studio Debug Tips

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

  19. CFormView

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

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

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