Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
file read problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Art Cummings, post: 3165403"] 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; } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
file read problem
Top