0
我是一個noob在這個,並想知道爲什麼我的數組將在while循環內正確輸出,但一旦我cout數組以外的while循環沒有信息顯示? 如果你可以用初學者的術語解釋它真的很感激它。數組在循環內正確顯示,但一旦在數組外部似乎丟失所有信息
void Video::Read_Video()
{
ifstream Din;
Din.open("Video.txt");
if(!Din)
cerr << "Could not open video.txt for reading." << endl;
else
{
for(int i=0; i < Num_Of_Videos; i++)
{
while(Din.good())
{
getline(Din, Video_Array[i]);
Num_Of_Videos++;
cout << "Set_Video says these are the movies" << Video_Array[i] << endl;
}
cout << "Set_Video says these are the movies" << Video_Array[i] << endl;
}
Num_Of_Videos = Num_Of_Videos-2;
}
Din.close();
}
由於「i ++」,我將增加一個每個成功的循環我有一個文本文件中的五行,我試圖一次讀入一行中的字符串數組的五個不同成員「Video_Array [ ]」。第一個循環是將文本文件中的行分配給數組中的5個不同成員。第二個是計算for循環的文本文件中的行數。 – miike
**對於**循環的每個成功循環,'i'將增加1。但是你的閱讀發生在** while循環中。 * while *循環內沒有增加'i'。我仍然不明白你爲什麼有兩個循環。 –
好吧,我剛剛得到你所指的。這解決了它。非常感謝 – miike