m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-01-04 23:09:14 -0500
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-01-04 23:09:14 -0500
commit6b7244cfc47c4106fe769b4191416b389838a133 (patch)
tree828bac014aa719586b558c73d95542687324521a /src
parenta13f7f90743ccdf72e4e3196e666a23c26b896ec (diff)
Read edges until end of file
Diffstat (limited to 'src')
-rw-r--r--src/parse.h21
1 files 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 <fstream>
#include <set>
+#include <sstream>
+#include <string>
#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);
}
};