Read all lines: ifstream file("data.txt"); string line; while(getline(file, line)) { process(line); }. This handles files of any size without loading everything into memory first. Write CSV: ofstream file("output.csv"); for(auto& row : data) { file << row.id << "," << row.name << "\n"; }.
Separate fields with commas, rows with newlines. Copy file: ifstream in("src.txt"); ofstream out("dest.txt"); out << in.rdbuf();. The rdbuf() method returns a buffer you can stream directly, fastest way to copy entire files.