我正在编写一段简单的代码,用于识别文本文件中的偶数和奇数
下面是我的代码,我认为惟一的错误是while循环中的感叹号
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int even = 0, odd = 0;
int value;
ifstream file3("evenodd.txt");
while (!file3.eof) {
file3 >> value;
if (value % 2 == 0) {
even++;
}
else {
odd++;
}
cout << " Even count: " << even << " ";
cout << "Odd count: " << odd << " ";
}
}发布于 2020-04-23 04:04:06
eof是一个函数,所以代码需要看起来像这样的while (!file3.eof())。
https://stackoverflow.com/questions/61373934
复制相似问题