csv icon indicating copy to clipboard operation
csv copied to clipboard

Option to append to file when writing

Open jwillikers opened this issue 4 years ago • 1 comments

This is same use case as #16 except for writing to a file. An option to have the writer append to an existing file would be very helpful. Even better might be adding a csv::Writer constructor which takes a std::ostream.

jwillikers avatar Mar 10 '20 14:03 jwillikers

I think you need to modify the header file: /include/writer.hpp。 Below is what I've add to ctor:

#include <sys/stat.h>

// in the ctor:
// check if the file already exits
struct stat buf;
if (stat(file_name.c_str(), &buf) != -1)
{   
    header_written_ = true;
    file_stream.open(file_name, std::ios::app);
} else
{
    file_stream.open(file_name);
}

williamlfang avatar Mar 25 '20 07:03 williamlfang