C# has a nice static method
String.Format(string, params string[]);
that returns a new string with the formatting and values that are provided. Is there an equivalent in C++?
The reason is because I'm using log4cxx and want to take advantage of the macros like
LOG4CXX_DEBUG( logger, expr );
that uses short-circuit evaluation so that expr is never evaluated if the log level DEBUG is not enabled.
Currently, in C++, I do it like this:
CString msg;
msg.Format( formatString, values... );
LOG4CXX_INFO( _logger, msg );
which is defeating the purpose since I have to allocate and format the string first so there isn't nearly as efficiency coming out of the short-circuit logic.
There's a similar problem when trying to do simple logging with numerical values. This, won't compile:
LOG4CXX_DEBUG( _logger, "the price is " + _some-double_);
So I end up having to write something like this:
CString asStr;
asStr.Format( "%d", _some-double_ );
LOG4CXX_DEBUG( _logger, "the price is " + asStr );
which again defeats the purpose.
I'm not at all a C++ expert so I'm hoping more knowledgeable people can help.