Source File: ex20_v2_v3.diff
--- ex20_v2.cpp 2026-04-12 10:36:49.666521626 -0400
+++ ex20_v3.cpp 2026-04-12 10:36:57.531303795 -0400
@@ -5,13 +5,16 @@
using std::vector, std::string, std::ifstream, std::ios;
using fmt::println, fmt::print;
+using Row = vector<int>;
+using Table = vector<Row>;
+
int chunk_number(const string& line, size_t start, size_t end) {
string chunk = line.substr(start, end - start);
return stoi(chunk);
}
-vector<int> parse_line(const string& line) {
- vector<int> result;
+Row parse_line(const string& line) {
+ Row result;
size_t start = 0;
size_t end = line.find(",", start);
@@ -32,8 +35,8 @@
int main(int argc, char* argv[]) {
string filename{argv[1]};
- ifstream in_file(filename, std::ios::binary);
- vector<vector<int>> table;
+ ifstream in_file(filename, ios::binary);
+ Table table;
if(!in_file.is_open()) {
println("failed to open {}", filename);
@@ -47,11 +50,11 @@
if(line == "") break;
- vector<int> row = parse_line(line);
+ Row row = parse_line(line);
table.push_back(row);
}
- for(vector<int> row : table) {
+ for(Row row : table) {
for(int cell : row) {
print("{}\t", cell);
}