문제

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.

도움이 되었습니까?

해결책

You can replace it with an empty string object:

oss.str(std::string());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top