I want to add a new line in file so i can print output results. Basically i am using same file for input and output. Input already exist in file but now i want to print my new output in new line.
I tried using output.eof or input.eof and vice versa but it just overwrites input that was already present in file.
```
while (!fin.eof()){
fin.get(value);
if (fin.eof()){
fout << 1;
}
}
```
you have to open the file for output and write the value at the end. you can open it in append mode (ios::ate I think, look up the code you want) and just write to it...
ofstream fout(filename, ios::ate);
fout << endl;
fout.close();
Use either std::ofstream::ate or std::ofstream::app when opening a file to add content to the end.
Preferable to use std::ofstream::app if you want to write multiple times to your file, it seeks to the end of the stream with each write. std::ofstream::ate only seeks to the end of the stream after the open.
ios::app is funky looking, but all it is doing is fetching a constant from the global namespace.
it is just like how you will see
std::cout << "hello";
ios::app is an integer code that tells the open() function what to do. Its not complicated, just different syntax to what you are used to seeing.
you may want to re-read Furryguy's post. I am on a journey to get my code out of the 90s and sometimes use older forms for things like this that I haven't mentally updated yet :) Its doing the same thing, but using an updated form, is all.
ios, by the way, is probably just 'Input/Output/Stream' or something to that effect, an acronym.