I am fairly new to C++ and am in a Programming I course in school. We have been assigned to create a program that uses multiple functions. The professor has given us code for two of the functions, one to open a file and then another one to read the files contents and output them. I have put these into my program but they will not execute. The program does run, but the functions themselves are not executing. I have practiced with other functions that contain no parameters and those run fine, but the functions she gave us have multiple parameters. If someone could please let me know what I am doing wrong, I would GREATLY appreciate it.
The code I have so far is below:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
void PrintFile (string FileName, ifstream& inFile);
int main ()
{
ifstream inFile;
string fileName;
// This next block of code opens the file, this needs to be a separate function but does not work when put as one.
cout << "Enter the name of the file that you want to analyze: ";
cin >> fileName;
inFile.open(fineName.c_str());
if (inFile)
{
cout << endl << "The file was opened successfully!" >> endl;
}
else
{
inFile.clear ()
cout << "Can not open file." << endl;
}
void PrintFile (string fileName, ifstream& inFile);
return 0;
}
void PrintFile (string fileName, ifstream& in File)
{
char ch;
cout << "The contents of the file" << fileName << ":" << endl;
inFile.get (ch);
while (inFile)
{
cout << ch;
inFile.get (ch);
}
}