File modes control how files open. Specify them as a second argument: ofstream file("data.txt", ios::app);. Common modes: ios::in (read), ios::out (write, truncate), ios::app (append), ios::binary (binary mode).
Combine modes with | (bitwise OR): file.open("log.txt", ios::out | ios::app);. This opens for writing in append mode, new data goes at the end without erasing old content. ifstream defaults to ios::in, ofstream defaults to ios::out (truncating).
If you want both read and write, use fstream with ios::in | ios::out. Modes prevent accidental overwrites and clarify intent.