Can i design my logging-function in a way, that it accepts concatenated strings of the following form using C++?
int i = 1;
customLoggFunction(\"My Integer i
For trivial projects this is one of the few things I use a MACRO
for. You can do something like this:
#define LOG(m) do{ std::cout << timestamp() << ": " << m << '\n'; }while(0)
// ...
LOG("error: [" << errno "] " << filename << " does not exist.");
Generally MACROS
should be avoided but there is no other way to get precisely this with a standard function. So...
Note: The empty condition do{...}while(0)
enables you to place the MACRO
in places that a MACRO
usually can't go if it contains multiple statements.