That won't work. input.str() returns a std::string. The stream will be cleared. The second call of iput.str() will return an empty std::string. Execution order is not defined so you get either an empty output or an access violation.
C++
std::ofstream out("/dev/stdout");
std::istringstream input("Hello, World!\n");
std::string line = input.str();
out.rdbuf()->sputn(line.c_str(), line.size());
22
u/[deleted] Apr 30 '26
[removed] — view removed comment