Overwrite on int with fstream

Hello everyone. First off, not only am I just starting with C++ but this is also one of my first posts on this forum, so I'm sorry if this is in the wrong place or something.
Anyway, I'm trying to overwrite a certain line of a text file. While I have found solutions on the web, they all work by the search function. I need to print to a certain line (ex. print 8 on line 3) without knowing the current int on that line. The code I have written so far only writes, so any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    // Write other stats to file
        ofstream outFile ("playeronestats.txt", ios::out | ios::app);
        if (type == 1) {
            cout << "So your a warrior huh" << endl;
            outFile << "100 \n"; // HP
            outFile << "30 \n"; // MANA

            }

        if (type == 2) {
            cout << "So your a wizard huh" << endl;
            outFile << "80 \n"; // HP and end-line
            outFile << "50 \n"; // MANA and end-line
            outFile << "0 \n"; // GOLD and end-line

            }

        else {

            cout << "Please select a valid type \n"; // ERROR MESSAGE and end-line 
            return 0;
            
            }
      outFile.close();

Thanks for any help you can give :)
Opening an ofstream with the ios::app will never overwrite, it will only append. I don't understand the part of the question about
"I need to print to a certain line ..."


BTW, you should write:
"So you're a warrior, huh?"
When I say I need to print to a certain line I mean if I have a file with say
1
2
3
4

I want to replace 3 with 2 so it reads
1
2
2
4

And thanks for catching that :)
The easiest way is to read from the existing file and write the desired items to a new file, then delete or rename the original file and rename the new file to the original name.
Topic archived. No new replies allowed.