From fa0cf9fa668a9fc2a034d9c4ba60a78d1e558482 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 30 May 2022 19:07:54 +0300 Subject: Autocommit at 30.05.2022 @ 19:07 --- src/Models/Table.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/Models/Table.cpp') diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index b29b075..2b4eb6c 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -6,16 +6,27 @@ #include #include #include +#include -void Table::readFromFile(std::ifstream inFile) { - +unsigned countOfCommas(std::ifstream& file) { + unsigned commaCount = 0; + while (file.peek() != '\n') { + if (file.get() == ',') commaCount++; + } + return commaCount; +} + +void Table::readFromFile(std::ifstream& inFile) { + unsigned commaCount = countOfCommas(inFile); + cells = List>(commaCount + 1); } Table::Table(const char* filePath) { std::ifstream inFile(filePath); if (inFile.is_open()) - throw new std::logic_error("Could now open file!"); - cells = List>(); + throw std::logic_error("Could now open file!"); + readFromFile(inFile); + inFile.close(); } Table::Table(unsigned rows, unsigned cols) { -- cgit v1.3.1-23-gd82d