How to use my logging class like a std C++ stream?

前端 未结 5 1874
借酒劲吻你
借酒劲吻你 2020-12-24 15:34

I\'ve a working logger class, which outputs some text into a richtextbox (Win32, C++). Problem is, i always end up using it like this:

stringstream ss;  
ss          


        
5条回答
  •  粉色の甜心
    2020-12-24 16:17

    Overloading the insertion operator<< is not the way to go. You will have to add overloads for all the endl or any other user defined functions.

    The way to go is to define your own streambuf, and to bind it into a stream. Then, you just have to use the stream.

    Here are a few simple examples:

    • Logging In C++ by Petru Marginean, DDJ Sept 05th 2007
    • Rutger E.W. van Beusekom's logstream class, check also the .hpp alongside with this file

提交回复
热议问题