I need help running my program this is what it asks me for "Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the screen. If the file has fewer than 10 lines, the entire file should be displayed along with a message indicating the entire file has been displayed" I think i have coded the program correctly but when I try to run it, it doesnt run...please help... this is what i have so far...
Thanks in advance...
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
// Variables needed to read file one character at a time.
const int LENGTH = 81;
fstream file;
char ch, fileName[LENGTH];
// Get file name and open file.
cout << "Enter a file name: ";
cin >> fileName;
file.open(fileName, ios::in);
if (!file)
{
cout << fileName << " could not be opened.\n";
return 0;
}
// Read file one character at a time and echo to screen.
file.get(ch);
while (!file.fail())
{
cout << ch;
file.get(ch);
}
// Close file
file.close();
return 0;
}