O
Old Wolf
#include <iostream>
#include <ostream>
#include <sstream>
int main(void)
{
std:stringstream oss;
oss << "foo";
oss.str("APP");
std::cout << oss.str() << '\n';
oss << "END";
std::cout << oss.str() << '\n';
oss.str("");
oss << "APP";
std::cout << oss.str() << '\n';
oss << "END";
std::cout << oss.str() << std::endl;
return 0;
}
I expected to see the output:
APP
APPEND
APP
APPEND
but the second line said "END" instead. Why is this?
What is the best way to set the string in an ostringstream,
and leave it in a usable state?
#include <ostream>
#include <sstream>
int main(void)
{
std:stringstream oss;
oss << "foo";
oss.str("APP");
std::cout << oss.str() << '\n';
oss << "END";
std::cout << oss.str() << '\n';
oss.str("");
oss << "APP";
std::cout << oss.str() << '\n';
oss << "END";
std::cout << oss.str() << std::endl;
return 0;
}
I expected to see the output:
APP
APPEND
APP
APPEND
but the second line said "END" instead. Why is this?
What is the best way to set the string in an ostringstream,
and leave it in a usable state?