Im a noob at this and was wondering why my array will output correctly within the while loop but once i cout the array outside of the while loop no information is displayed?
if you can explain it in beginner terms id really appreciate it.
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();
}
Your loop don’t make any sense. Inside the
forloop,iis not incremented. So you keep reading into the same element ofVideo_Array. It’s not clear exactly what it is you’re trying to do, but the code as written doesn’t make much sense. Why do you have two loops?