Referring to http://stackoverflow.com/questions/303562/c-format-macro-inline-ostringstream
The question there was for a macro that allows inline concatenation of objects to create a string, iostream-style.
The answer was:
#define SSTR( x ) dynamic_cast< std::ostringstream & >( \
( std::ostringstream().seekp( 0, std::ios_base::cur ) << x ) \
).str()
Usage (for example):
throw std::runtime_error(
SSTR( "FooBar error: Value " << x << " exceeds " << y )
);
That works beautifully - with GCC. It compiles and runs under Visual C++ 2005, too. But with the latter, all uses of the macro result in empty strings, and I am quite dumbfounded as to why, and how to fix it...?