Help With Executing Multiple Functions!

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:

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#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);
  }
}
line 16 should be:
inFile.open(fileName.c_str());

watch those tYpOs

line 28 should be:
PrintFile (fileName, inFile);

You are giving a command not creating a function header
Last edited on
Topic archived. No new replies allowed.