but I didnt understand why all output streams would truncate so when i looked it up online, I found the code below, which doesnt mention trunc, so I am wondering. is trunc set normally or is my book wrong?
void open (constchar* filename, ios_base::openmode mode = ios_base::out);
Those snippets are showing how the "default" open mode is defined. And don't forget with modern C++ (C++11 or better) you can also use std::string, or a std::filesystem::path as the first parameter.
Things to understand about an ofstream:
1. An ofstream is always an output stream (note the "=" in those snippets).
2. By default an ofstream truncates the file when opening.
3. You need to use a different open mode to avoid the truncation (std::ios::app).