我正在尝试读取文本文件并将其存储在数组中,但我的程序一直处于无限循环中。将数据文件读入数组
这里是我的代码:
int main() {
const int size = 10000; //s = array size
int ID[size];
int count = 0; //loop counter
ifstream employees;
employees.open("Employees.txt");
while(count < size && employees >> ID[count]) {
count++;
}
employees.close(); //close the file
for(count = 0; count < size; count++) { // to display the array
cout << ID[count] << " ";
}
cout << endl;
}
你试过在调试器中运行它吗? – anishsane
您确定这是您的确切代码吗?我只是试了一下,它的工作。 – BoBTFish
无限循环?你的代码每个循环最多可产生10000次迭代... – Geoffroy