From dfed677a8a8e6d0d75d14ed9626c16184ff4f066 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 30 May 2022 21:28:44 +0300 Subject: Autocommit at 30.05.2022 @ 21:28 --- src/Models/Table.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Models/Table.cpp') diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 506204a..75c5e70 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -32,6 +32,9 @@ bool containsNumber(const char*& str) { #include void Table::readFromFile(std::ifstream& inFile) { unsigned commaCount = countOfCommas(inFile); + if (commaCount == 0) + throw std::logic_error("Expected at least the first line to have data."); + unsigned colInd = 0; cells.add(List(commaCount)); while (inFile.peek() != EOF) { @@ -60,7 +63,7 @@ void Table::readFromFile(std::ifstream& inFile) { } if (isDigit(inFile.peek())) - throw std::logic_error(fileLocationExceptionMsg("Error: Expected digit but got something else at row ", cells.get_count(), inFile.tellg() % cells.get_count() + 1)); + throw std::logic_error(fileLocationExceptionMsg("Error: Expected digit but got something else at row ", cells.get_count(), inFile.tellg() % commaCount)); // Parsing digits of whole number/whole part of floating point number while (isDigit(inFile.peek())) { @@ -76,7 +79,7 @@ void Table::readFromFile(std::ifstream& inFile) { } if (inFile.peek() != ' ' && inFile.peek() != ',' && inFile.peek() != '\n') - throw std::logic_error(fileLocationExceptionMsg("Error: Expected space, comma or newline but got something else at row ", cells.get_count(), inFile.tellg() % cells.get_count() + 1)); + throw std::logic_error(fileLocationExceptionMsg("Error: Expected space, comma or newline but got something else at row ", cells.get_count(), inFile.tellg() % commaCount)); if (exponent == 1) cells[cells.get_count() - 1][colInd++] = new CellInt(whole); -- cgit v1.3.1-23-gd82d