Homework: reading from file

Hi Guys,
I am in a C++ class, my homework assignment is to ask a user for a file name. when they input the file name it should display 24 lines of output at a time an then pause and wait for the user to press a key before it will output the next 24 lines. My code is below, but it does not show the 24 output lines, its all blank. can someone please explain what i did wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() 
{
	//gets file name
	cout << "Please enter the name of the file: ";
	string fileName;		//holds file name
	getline(cin, fileName);	//

	ifstream file(fileName.c_str(), ios::out);

	string line;
	for (int count = 1; !file.eof(); ++count)
	{
		getline(file, line);

		cout << line << endl;
		if (count % 24 == 0) 
	system("Pause");
	}
}


the file i am using is a text file named 'random' a sample of the text file is below

42
468
335
501
170
725
479
359
963
465
706
146
282
828
962
492
996
943
828
437
392
605
903
154
293
383
422
717
719
896
448
727
772
539
Mann you're good, works perfectly. Just that when entering the filename, you must enter the file extension also--in this context, .txt

Hope it HELPS!!!
Topic archived. No new replies allowed.