我刚刚将文本文件中的数据读入一维数组。我的“for”语句没有从数组中输出数据。我想输出整个数组只是为了验证所有数据都在那里。但是,当我输出单个单元格时,数据会输出到屏幕上。我究竟做错了什么?提前致谢!
#include <iostream>
#include <fstream>
#include <iomanip>
int main()
{
const int MAX_CELLS = 500;
int count = 0;
double Vehicles[MAX_CELLS];
ifstream vehicleFile;
char type;
string license;
double charge;
vehicleFile.open ("VEHICLE.txt");
if (!vehicleFile)
cout << "Error opening vehicle file " << endl;
vehicleFile >> type >> license ; // priming read
while (vehicleFile) { // while the read was successful
cout << count << " " << license << endl; // FOR DISPLAY ONLY
vehicleFile >> Vehicles[count]; // read into array
count++; // increment count
vehicleFile >> type >> license; // read next line
}
cout << showpoint << fixed << setprecision(2);
for ( count; count < MAX_CELLS; count++) {
cout << "Array #" << count << "is: "; // OUTPUT ARRAY
cout << Vehicles[count] << endl;
}
cout << Vehicles[8]; // READS DATA IN CELL
vehicleFile.close();
system ("pause");
return 0;
}