file reading and writing

My files are not seeming to open properly. I need to open and read scores.txt, and then I need to open and write to stats.txt. I'm not seeing what Im doing wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  ifstream fin ("stats.txt");
    ofstream fout ("scores.txt");
    
    fin.open("scores.txt");
    
    if (fin.fail())
    {
        cout << "Cannot open file to read ( scores.txt )" << endl;
        exit(1);
    }
    
    fout.open("stats.txt");
    
    if (fout.fail())
    {
        cout << "Cannot open file to read ( stats.txt )" << endl;
        exit(1);
    }
I'm not seeing what Im doing wrong.
Trying to open already opened stream.

I need to open and read scores.txt
Why then do you have ifstream fin ("stats.txt");. Wouldnt it be more logical to have ifstream fin ("scores.txt"); and drop call to open()?

Same for output.
I had it that way to begin with but the file won't open. I have it in the same folder as the .cpp file too.
Does folder with cpp file is working folder of your program?
Does program have permissions to read from this folder?
how do I figure that out?
Topic archived. No new replies allowed.