From c75d66d2b4b186cd7ac1f12e53c9df18aba31537 Mon Sep 17 00:00:00 2001 From: Mauro Massari Date: Fri, 21 Mar 2025 11:37:40 +0100 Subject: [PATCH] Fix bug when reading zero DA from ascii file --- interfaces/cxx/DA.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/interfaces/cxx/DA.cpp b/interfaces/cxx/DA.cpp index 7765539..aa6dbf7 100644 --- a/interfaces/cxx/DA.cpp +++ b/interfaces/cxx/DA.cpp @@ -1806,12 +1806,29 @@ std::istream& operator>>(std::istream &in, DA &da){ } } - // read the istream until end string is found and put each line in the string vector (end condition taken from daceio.c) - for(getline(in, line); in.good() && (line.compare(4, 31, endstr, 0, 31) != 0); getline(in, line)) - strs.push_back(line); + if (!strs.empty()) + { + if(!strs.back().empty()) + { + // check that last line is not the terminator line and in case remove it + if(strs.back().compare(4, 31, endstr, 0, 31) == 0) + { + strs.pop_back(); + + } + else + { + // read the istream until end string is found and put each line in the string vector (end condition taken from daceio.c) + for(getline(in, line); in.good() && (line.compare(4, 31, endstr, 0, 31) != 0); getline(in, line)) + strs.push_back(line); + } + } + // convert string vector to DA + da = DA::fromString(strs); + } + - // convert string vector to DA - da = DA::fromString(strs); + } return in;