Using void to send an error message

So for a project I am needed to use a void function for when the file is asked for the user inputs the file name and the void function then checks to see if the file is actually there or not. If it is then it moves on, if not it is to display the error message below. I am not asking for code, but perhaps more clarification on my errors that I am getting. I do leave out or mess up in simple ways and may be overlooking something.

So my code works fine without this function, but after I put it under the main function it gives me errors like "expected initializer before 'string'" and a couple of expected constructor, deconstructor, or type conversion and expected unqualified id before the if and else lines.

The prototype declaration about the int main is void inputErr() because there is no value being given. If the rest of the code is needed I can provide that but this was the chunk I was having problems with.
Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  void inputErr()


    string filename;
    cout << "Name your file> ";
    getline( cin, filename );
    fstream file( filename.c_str() );
    if (!file)
    {
        cout << "\n\n\n************************************";
        cout << "\nERROR!\tERROR!\tERROR!\tERROR!\tERROR!\n";
        cout << "\n\n\tInput File Not Found!\n\n";
        cout << "      Exciting With Error : No file";
        cout << "\n\n\n************************************";
        cout << "\n\n\n\n\n\n";
    return;
    }
  else
Last edited on
Well I fixed all but one error so far with moving one of the brackets from on top of the cout statements to right under the void area. I also removed the else from the whole project and now it doesn't throw any errors but it doesn't work properly still.
Topic archived. No new replies allowed.