質問

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