로그인

검색

C/C++
2013.07.28 02:44

Simplified Logger Class

MoA
조회 수 3325 추천 수 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. printf Type Field Characters

  3. Property Sheet의 버튼 속성 변경하기

  4. pthread

  5. PyTorch 딥러닝 챗봇

  6. Quake 3 source code and review

  7. R language 사이트

  8. RAND_MAX

  9. Real-Time Stock News Sentiment Prediction with Python

  10. Redmine 설치

  11. Reinforcement Learning for Dynamic Pricing Suggestion

  12. RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED ...

  13. SciPy and NumPy

  14. Serial Communication in MFC

  15. Simple Add-On Wait Dialog in MFC

  16. Simplified Logger Class

  17. Sleep() 함수 대신 프로그램 딜레이 시키기 (Wait)

  18. SSH-Tunneling을 통한 MySQL 서버 연결

  19. Stable Diffusion

  20. Start Something! - Windows 8 개발 공식 사이트

  21. stdafx.h 사용 (미리 컴파일된 헤더)

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