Answers for "csv file management using c++"

C++
0

csv file management using c++

// csv.d

void main() {

    import std;


    File[string] outputFiles;

    auto inputFile = File("input.csv");

    auto lines = inputFile.byLine;

    lines.popFront; // skip header


    foreach (line; lines) {

        const name = line.splitter(',').front;

        // open output file if not already open in append mode 

        if (name !in outputFiles) { 

            outputFiles[name] = File(name ~ ".csv", "a");
        }

        outputFiles[name].writeln(line);
    }
}
Posted by: Guest on April-12-2021

Code answers related to "csv file management using c++"

Browse Popular Code Answers by Language