【发布时间】:2010-12-14 17:55:46
【问题描述】:
我正在尝试使用迭代器初始化字符串,类似这样的工作:
ifstream fin("tmp.txt");
istream_iterator<char> in_i(fin), eos;
//here eos is 1 over the end
string s(in_i, eos);
但这不是:
ifstream fin("tmp.txt");
istream_iterator<char> in_i(fin), eos(fin);
/* here eos is at this same position as in_i*/
//moving eos forward
for (int i = 0; i < 20; ++i)
{
++eos;
}
// trying to initialize string with
// pair of iterators gives me ""
// result
string s(in_i, eos);
谢谢。
【问题讨论】:
-
如果代码被格式化(缩进 4 个字符)以便我们阅读它会很有帮助。
-
与其抱怨,马克,你可以修复它。你有它的声誉分数。
-
@Rob:当一个问题由其他人编辑几次时,它会自动成为社区 Wiki。此外,通过让作者更正帖子,您可以确保他/她将来知道如何做。我看不出马克的评论有什么问题,而且(来自非母语人士)它似乎并不苛刻但很有帮助
标签: c++ string iostream libstdc++