如何做是>> std :: skipws>>通过数组的多个索引?

发布于 2025-01-28 03:01:15 字数 346 浏览 4 评论 0原文

假设您有std :: array< int,size>一个,您将a的每个元素保存到一个由空间隔开的行中的文件中。然后,您想使用std:istream&阅读它们。 IS via:

is >> std::skipws >> a[0] >> a[1] >> a[2] >> ... >> a[SIZE-1];

如何为大小的任何值写入此操作。即使还有其他简单的方法可以做到这一点,我很好奇通过这种特定方法完成的工作。

Let's say you have std::array<int, SIZE> a, and you have saved each element of a into a file in one line separated by a space. Then you want to read them with a std:istream& is via:

is >> std::skipws >> a[0] >> a[1] >> a[2] >> ... >> a[SIZE-1];

How to write this generically for any value of SIZE. Even though there are other easy ways of doing this, I'm curious how it is done with this particular method.

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

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

发布评论

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

评论(1

破晓 2025-02-04 03:01:15

如何为任何大小的任何值写入此。

有用于重复操作的控制结构可变数量:循环

例如:

is >> std::skipws;
for(auto& el : a) {
    is >> el;
}

How to write this generically for any value of SIZE.

There are control structures for repeating an operation a variable number of times: loops.

For example:

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