A
Art Cummings
Hello, i'm trying to read a file 24 lines at a time for a beginning c++
problem. The code doesn't stop when it has 24 lines but continues to read.
Can someone assist with why it doesn't stop at 24 lines?
Thanks
Art
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
int main()
{
string input, fileName;
cout << "Enter a file name: ";
getline( cin, fileName );
ifstream nameFile( fileName.c_str() );
if (!nameFile )
{
cerr << fileName << " The file could not be opened.\n";
system("PAUSE");
return 0;
}
int count = 0;
while( nameFile )
{
getline(nameFile, input);
cout << input << endl;
++count;
if( count==24 )
{
_getch();
count=0;
//system("PAUSE");
}
}
nameFile.close();
system("PAUSE");
return 0;
}
problem. The code doesn't stop when it has 24 lines but continues to read.
Can someone assist with why it doesn't stop at 24 lines?
Thanks
Art
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
int main()
{
string input, fileName;
cout << "Enter a file name: ";
getline( cin, fileName );
ifstream nameFile( fileName.c_str() );
if (!nameFile )
{
cerr << fileName << " The file could not be opened.\n";
system("PAUSE");
return 0;
}
int count = 0;
while( nameFile )
{
getline(nameFile, input);
cout << input << endl;
++count;
if( count==24 )
{
_getch();
count=0;
//system("PAUSE");
}
}
nameFile.close();
system("PAUSE");
return 0;
}