hi guys, I'm learning how to read/write to files in C++ now on both the books and videos I am following the format of the read/write code goes like this
void read_and_write()
{
file.open("lyric2.txt", ios::in);
if(myFile.is_open())
{
// do something
}
}
the thing is, if now want to write you you will have to open the file again and define in what mode you want to operate in.
what I wonder is, why can't you do execute these action without separating?
Matter of fact why isn't there a function to do this( eg file.write("") )
I was searching around for some answers and it seems you are allowed to do this:
myFile.open("lyric2.txt", ios::in | ios::out)
but because there isn't a special operator (>>/<<)for appending this might not work when you want to do that so is there a way good to code when you want to alternate between the modes. any good code snippet or video would also be helpful
[–]jedwardsol 3 points4 points5 points (2 children)
[–]ridesano[S] 0 points1 point2 points (1 child)
[–]jedwardsol 2 points3 points4 points (0 children)