csv files in c++ code example
Example: 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);
}
}