Closed yycsysu closed 11 years ago
Yeah. This is obvious. So GetNext
must be called before word
. Do you think that this API design isn't good enough? En, you are in the right place! However, these method is used for adding stuff to this class.
Also notice that in the file_interface.h
line 27,
FileInterface() : current_word_pos_(-1) {}
while (f.GetNext()) { std::cout << counter++ << " "<< f.word() << std::endl; }
GetNext是要对当前位置current_wordpos 加1并判断,要是current_wordpos 初始为0下面就不能像举例一样输出第一个单词了,但是要是current_wordpos 初始为-1的话要是没用GetNext就会出错了。