From 2817ade782cc13b8f42d9616e4b3a935400b5179 Mon Sep 17 00:00:00 2001 From: Omar Alvarez Date: Mon, 22 Jun 2020 13:40:15 +0200 Subject: [PATCH] Fix parsing label files with unexpected chars --- src/Int8BatchStream.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Int8BatchStream.cpp b/src/Int8BatchStream.cpp index dd4399f..fdc1db2 100644 --- a/src/Int8BatchStream.cpp +++ b/src/Int8BatchStream.cpp @@ -132,21 +132,14 @@ void BatchStream::readCVimage(std::string inputFileName, std::vector& res void BatchStream::readLabels(std::string inputFileName, std::vector& ris) { std::ifstream is(inputFileName.c_str()); - //read only the first number: the image sub-portion class - while (true) { + + std::string line; + while (std::getline(is, line)) + { + std::istringstream iss(line); float val; - is >> val; - if (!is) { - break; - } - // insert the first number and skip all others + if(!(iss >> val)) { break; } // error ris.push_back(val); - while( true ) { - char c; - is >> c; - if (is.peek() == '\n') //detect "\n" - break; - } } }