设置 ostringstream 自动追加

发布于 2024-11-08 15:31:57 字数 309 浏览 2 评论 0原文

如何为 ostringstream 对象附加数据?假设:

ostringstream oss;
oss << '0x11';

我如何设置它来执行 oss << 0x22 自动从最后一个已知元素开始?我读到我需要设置一些标志,但我该怎么做呢?

编辑:很抱歉这个问题非常含糊。可能咖啡已经快没了。从我上面的问题延伸:

ostringstream oss(osstringstream::app) 是否将其设置为每次追加?我的目标是创建一个字符串。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乜一 2024-11-15 15:31:57

未指定 app 标志传递给
ostringstream 构造函数。该标志仅与
ofstream。另一方面,ostringstream一个流,
因此,数据总是插入到先前的数据之后
插入数据,前提是在此期间没有发生寻道。毕竟,这是输出流的定义。

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.

雅心素梦 2024-11-15 15:31:57

当您像第一个示例一样创建 stringstream 时,它会默认追加。

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

も星光 2024-11-15 15:31:57

这就是 ateapp 作为开放模式的区别。打开后将ate位置放在最后,然后保留写入位置(所以如果你想要的话,你可以在任何地方写入),app确保所有写入都在最后完成流的。

编辑:实际上 stringstream 的行为不同,所以不要依赖它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文