Include the O_APPEND
flag when opening the file. See the reference page for _open()
.
As this is C++ consider using an ofstream
instead. These are type-safe and remove the requirement of having to specify the length of the arguments being written to the file:
std::ofstream out(full_path, std::ios_base::app);
if (out.is_open())
{
out << "----Session----\n\n"
<< "Date/Time: " << datetime << "\n\n"
<< "Text: " << text << "\n\n\n\n";
}