I have been using the following code to clear std::stringstream
:
m.swap(std::stringstream());
Code probably taken from this SO thread. Recently I compiled my code in Visual Studio 2013 and I received the following warning:
warning C4239: nonstandard extension used : 'argument' : conversion from 'std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>' to 'std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>> &'
1> A non-const reference may only be bound to an lvalue
I did not receive any warning in earlier versions of Visual Studio using /W4. I recall I had trouble reliably clearing stringstreams in earlier versions which is why I ended up using that code in the first place.
So is it portable to clear a stringstream that way, and if not could you explain why not? Also is there a portable way to clear a stringstream? Thanks
Edit: Here is the code that was requested. Compile it using /W4
to see the warning.
int _tmain(int argc, _TCHAR* argv[])
{
std::stringstream m;
m.swap(std::stringstream());
return 0;
}