File Output

Can anyone explain to me why this simple file output program is not working? After running the program and entering some values, I check out the file but nothing gets written! :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
    string grade[10];
    fstream textfile;
    textfile.open("exam.txt");
    for(int x=0;x<10;x++){
        cout << "Enter a grade for a student: "; getline(cin, grade[x]);
    }
    for(int x=0;x<10;x++){
        textfile << grade[x] << endl;
    }
    textfile.close();
}
is your code able to open the file exam.txt?
I found what was wrong now, I had the file in the wrong folder so the code couldn't reach it.

is your code able to open the file exam.txt?

It wasn't able to open it, but the compiler didn't tell me that.
Last edited on
Topic archived. No new replies allowed.