CIS 2 Programming Assignment

Hey guys, i am having trouble finishing my program. Here's the program. I am getting an error saying my 'fin' is not declared. I also need to include a loop to allow the user to enter the file name twice before exiting if the file does not exist that they entered. Here is my program that i have typed up so far. If anyone has any answers that would be great. Thanks!

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void showContent(fstream &);

int main(void)
{
string fileName;
char line[100];
fstream fin;
fstream dataFile;

cout << "Please enter the Filename: " << endl;
cin >> fileName;

fin.open(fileName.c_str(), ios::in);
dataFile.close();

showContent(dataFile);

while(!fin)
{
cout << "Error Opening File! Re-enter File Name: " << endl;
cin >> fileName;
}

system("pause");
}

void showContent(fstream &file)
{
int counter = 0;
char getch();

while(!fin.eof())
{
if (counter > 21)
{
getch();
counter = 0;
}

fin.getline(line, 101, '\n');
cout << line << endl;
counter++;
}
}
fin is only available in main. Since showContent has a parameter file you should use it.
Also forget about eof(). It doesn't work like you expect. Google will tell you why.
Topic archived. No new replies allowed.