It works:
stringstream temp; temp << i; result_stream << transform(temp.str());
( transform is a function that takes a string and returns a string ; i is int ). However, my attempt to allow C ++ 11 to create a temporary object without a name does not work:
result_stream << transform((stringstream() << i).str());
I thought this would work, as the second << should just return the first argument, and I could use str() . But I get this error:
error: 'class std::basic_ostream<char>' has no member named 'str'
I am using g ++ 4.8.1 (MinGW-W64).
Is there a way to accomplish this (e.g. write such code using an unnamed temporary)? (The above code is a bit simplified, and the actual code involves using << for arguments other than int .)
source share