0

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.

Canvas
  • 5,779
  • 9
  • 55
  • 98

1 Answers1

1

You can replace it with an empty string object:

oss.str(std::string());
David G
  • 94,763
  • 41
  • 167
  • 253