stringstream temporary ostream return problem

前端 未结 2 761
别跟我提以往
别跟我提以往 2020-12-30 14:28

I\'m creating a logger with the following sections:

// #define LOG(x) // for release mode
#define LOG(x) log(x)

log(const string& str);
log(const ostrea         


        
2条回答
  •  心在旅途
    2020-12-30 14:53

    Alter your LOG() macro to this:

    #define LOG(x) do { std::stringstream s; s << x; log(s.str()); } while(0)
    

    That will let you use the following syntax in your debugging logs, so you don't have to manually construct the string stream.

    LOG("Testing" << 1 << "two" << 3);
    

    Then define it to nothing for release, and you'll have no extra allocations.

提交回复
热议问题