0
我有一个包含这些值的文件:在二维数组更换特定值
0 0 0
0 0 0
0 0 0
二维阵列是由下面的代码加载:
string Seats[10][10]; // creates array to hold strings
short loop1 = 0; //short for loop for input
short loop2 = 0; //short for loop for input
string line; //this will contain the data read from the file
ifstream BookingFile("test.txt"); //opening the file.
if (BookingFile.is_open()) //if the file is open
{
cout << "These are the available seats: \n" << endl;
while (!BookingFile.eof()) //while the end of file is NOT reached
{
getline(BookingFile, line); //get one line from the file
Seats[loop1][loop2] = line;
cout << Seats[loop1][loop2] << endl; //and output it
loop1++;
loop2++;
}
}
我现在想要做的是简单找到一种方法来改变数组中的特定值。我已经使用
array[rows][cols]
之前编辑这些值,但不会与一个文件,是外部的工作,我不似乎得到
seats << [rows][cols]
工作,所以什么是最好的如何做到这一点?
在这段代码中有很多错误,“while(!BookingFile.eof())”就是其中之一。 [**阅读这个了解为什么**](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong)。 – WhozCraig 2014-10-01 18:02:34