로그인

검색

C/C++
2013.07.28 02:44

Simplified Logger Class

MoA
조회 수 3328 추천 수 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 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views15455
    read more
  2. printf Type Field Characters

    Date2012.02.23 CategoryC/C++ By너울 Views3483
    Read More
  3. Property Sheet의 버튼 속성 변경하기

    Date2013.07.25 CategoryAPI/MFC ByMoA Views3260
    Read More
  4. pthread

    Date2013.07.28 CategoryLibrary ByMoA Views2627
    Read More
  5. PyTorch 딥러닝 챗봇

    Date2023.07.04 CategoryDeeplearning ByOBG Views2141
    Read More
  6. Quake 3 source code and review

    Date2014.01.15 CategoryTool/etc ByMoA Views3284
    Read More
  7. R language 사이트

    Date2012.02.08 CategoryTool/etc By너울 Views3079
    Read More
  8. RAND_MAX

    Date2014.01.19 CategoryC/C++ ByMoA Views3071
    Read More
  9. Real-Time Stock News Sentiment Prediction with Python

    Date2024.04.11 CategoryLLM ByOBG Views2416
    Read More
  10. Redmine 설치

    Date2013.07.28 CategoryTool/etc ByMoA Views3330
    Read More
  11. Reinforcement Learning for Dynamic Pricing Suggestion

    Date2023.04.01 CategoryDeeplearning ByOBG Views2526
    Read More
  12. RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED ...

    Date2022.09.06 CategoryDeeplearning ByOBG Views2644
    Read More
  13. SciPy and NumPy

    Date2013.12.23 CategoryPython ByMoA Views3065
    Read More
  14. Serial Communication in MFC

    Date2011.08.25 CategoryAPI/MFC By너울 Views3206
    Read More
  15. Simple Add-On Wait Dialog in MFC

    Date2013.11.21 CategoryAPI/MFC ByMoA Views3305
    Read More
  16. Simplified Logger Class

    Date2013.07.28 CategoryC/C++ ByMoA Views3328
    Read More
  17. Sleep() 함수 대신 프로그램 딜레이 시키기 (Wait)

    Date2013.07.28 CategoryAPI/MFC ByMoA Views8466
    Read More
  18. SSH-Tunneling을 통한 MySQL 서버 연결

    Date2023.04.21 Category서버 ByOBG Views2621
    Read More
  19. Stable Diffusion

    Date2022.09.27 CategoryDeeplearning ByOBG Views3287
    Read More
  20. Start Something! - Windows 8 개발 공식 사이트

    Date2012.08.02 CategorySite ByNaya Views3390
    Read More
  21. stdafx.h 사용 (미리 컴파일된 헤더)

    Date2012.08.13 CategoryAPI/MFC ByNaya Views3744
    Read More
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 15 Next
/ 15