新手问路:in.get()应该放while(){}里边还是外边?
代码如下
void A::upwords()
{
char ch;
while (!i.eof())//在stack overflow 上说用eof()不好,why?
{
i.get(ch);
if (ch=='I')
{
i.get(ch);
if (ch == 'S')
{
a += 1;
std::cout << a;
std::cout<< '\t' << ch << std::endl;
}
}
}i.close();
}和下面这个
void A::upwords()
{
char ch;
i.get(ch);
while (!i.eof())
{
if (ch=='I')
{
i.get(ch);
if (ch == 'S')
{
a += 1;
cout << a;
cout<< '\t' << ch << std::endl;
}
}
i.get(ch);
}
i.close();
}可是之前下面这个为什么运行不了?
顺便还问一个:
为甚吗while()里边用eof()不好?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4692/viewspace-3145874/ ,如需转载,请注明出处,否则将追究法律责任。