Question

At the moment I am storing some data into an output stream like so

std::ostringstream oss;
std::string fileData;

for(int i = 0; i < 4; i++)
{
    oss << i;
    fileData += oss.str();
}

now the output is this

1
1
2
1
2
3
1
2
3
4

How can I clear all the data inside my oss variable so this doesn't happen?

P.S. I know I could just declare a new outputstream every time but that seems quite extreme.

Was it helpful?

Solution

You can replace it with an empty string object:

oss.str(std::string());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top