【发布时间】:2013-09-16 13:03:36
【问题描述】:
如果我确定我的输入流包含 10 个值,我可以使用
std::copy_n(std::istream_iterator<T>(input), 10, output);
如果我不知道我有多少价值,我可以阅读所有的价值
std::copy(std::istream_iterator<T>(input), std::istream_iterator<T>(), output);
我的问题是如何读取最多 10 个值。我正在努力抵抗这里的 I/O 错误,
但似乎copy_n 会尝试读取输入的末尾(它不知道应该停止),而copy 不会在 10 个值处停止。我必须自己滚动copy_at_most吗?
(好吧,无论如何,copy_n 显然有些混乱:std::istream_iterator<> with copy_n() and friends)
【问题讨论】:
标签: c++