Another one of these, I've read a lot of topics here and around the web but I can't find the info I'm looking for.
I'm doing a project and I need to modify values in a .txt file, imagine it contains something like:
User gets asked a number from 3 to 5, and the program adds 1 to the corresponding line, so if user said 3, "3x3 0" would turn to "3x3 1". My initial problem was that the file got reset everytime I started the program, I then found out that ofstream and fstream with fstream::out reset the content, I put fstream::app so that didn't happen. Now I'm trying to use seekp to write to the correct place but it writes at the end, I know I used the append flag but shouldn't the pointer override that? I'm using the << operator to write, does seekp only affect certain fstream functions? Don't really get the logic that C++ uses for files.
Most importantly, I know I can use an ifstream that does getline to read everything and then passes it to a variable then uses a for loop to find the correct "nXn" line and adds 1 to the value there, finally writing all this to a temp file and renaming it to the original one overwriting it. However that seems like a roundabout way of doing things and I would like to know if there really isn't another way. If pointers work like I think they do I would like to use them. Basically point the input to the correct "0", read it to a int and add 1 to it, then point the output to the same place and overwrite the 0 with 1.