C # has a nice static method
String.Format(string, params string[]);
which returns a new line with the provided formatting and values. Is there an equivalent in C ++?
The reason is that I use log4cxx and want to use macros like
LOG4CXX_DEBUG( logger, expr );
which uses a short circuit estimate so that expr is never computed if the DEBUG log level is not enabled.
Currently in C ++ I am doing it like this:
CString msg; msg.Format( formatString, values... ); LOG4CXX_INFO( _logger, msg );
which defeats the goal, since I must first select and format the string, so the efficiency of the short circuit logic is not so high.
There is a similar problem when trying to do simple logging with numeric values. This will not compile:
LOG4CXX_DEBUG( _logger, "the price is " + _some-double_);
So I have to write something like this:
CString asStr; asStr.Format( "%d", _some-double_ ); LOG4CXX_DEBUG( _logger, "the price is " + asStr );
that defeats the goal again.
I'm not a C ++ expert at all, so I hope more knowledgeable people can help.