I am trying to append a sequence of matrices to disk as CSV and have found that using ios::ate overwrites any existing file created previously. To illustrate this problem via a simplified model, a second call to the function write_nums() below results in the loss of anydata written in the first call. Is there a way to fix this?
The solution to this question previously given in ofstream open modes: ate vs app does not seem optimal as it only works provided the file to which the output is directed already exists.
void write_nums()
{
std::ofstream out_file;
out_file.open("test.txt", std::ofstream::ate);
if (!out_file.good())
{
std::cerr << "Error while opening output file!" << '\n';
}
out_file.seekp(0, std::ios::end);
out_file << "{";
for (int i = 0; i < 10; ++i)
{
out_file << i << ',';
}
out_file.seekp(-1, std::ios::end);
out_file << "}";
}