문제

How do I append data for ostringstream objects? Assumingly:

ostringstream oss;
oss << '0x11';

How do I set it to perform oss << 0x22 from the last known element automatically? I read through that I need to set some flag but how do I do it?

edit: Sorry for being very very vague about the question. Prolly the coffee is wearing off. Extending from my question above:

Does ostringstream oss(osstringstream::app) sets it to append everytime? My goal is to creating a string.

도움이 되었습니까?

해결책

It is unspecified what the app flag does when passed to an ostringstream constructor. This flag is only relevant to ofstream. On the other hand, ostringstream is a stream, and as such, data are always inserted after the previously inserted data, provided no seek has occured in the meantime. This is, after all, the definition of an output stream.

다른 팁

When you create a stringstream like in your first example, it will append by default.

That's the difference between ate and app as open mode. ate position at the end after opening and then leave the write position alone (so if you want it, you can write anywhere), app ensure that all write is done at end of the stream.

Edit: in practice behaves differently for stringstream, so don't rely on it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top