From 6b7244cfc47c4106fe769b4191416b389838a133 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 4 Jan 2017 23:09:14 -0500 Subject: Read edges until end of file --- src/parse.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/parse.h b/src/parse.h index 52b8520..cb6e3c6 100644 --- a/src/parse.h +++ b/src/parse.h @@ -3,15 +3,16 @@ #include #include +#include +#include #include "graph.h" class Parser { public: Parser(std::string filename) : graph_(), input_file_(filename) { - parse_number_edges_(); - - for (int i = 0; i < number_edges_; i++) { - parse_edge_(); + std::string edge; + while (std::getline(input_file_, edge)) { + parse_edge_(edge); } } @@ -21,17 +22,11 @@ public: private: Graph graph_; std::ifstream input_file_; - int number_edges_; - - void parse_number_edges_() { - input_file_ >> number_edges_; - } - void parse_edge_() { + void parse_edge_(std::string edge) { int from, to; - - input_file_ >> from >> to; - + std::stringstream sstream(edge); + sstream >> from >> to; graph_.add_edge(from, to); } }; -- cgit v1.2.3