Hello all,
I have a text file set up as follows.
1 1 1
2 2 2
The program below is not reading the first line. The code below will only read 2 2 2. What am I missing here?
main.cpp
#include <iostream>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <cstddef>
#include <fstream>
#include <cctype>
#include <ctime>
#include <string>
#include <iomanip>
#include <queue>
using namespace std;#include "utility.h"
#include "Graph.h"
int main()
{
Graph g;
g.load_graph("GraphDemo1.txt");
}
Graph.h
#ifndef KEY_H
#define KEY_H
#include "utility.h"
class Graph
{
public:
Graph();
void load_graph(string fileName);
private:
int graph_size;
int matrix[25][25];
};
Graph::Graph()
{
}
void Graph::load_graph(std::string fileName)
{
ifstream fin(fileName.c_str());
if (!fin.is_open())
{
cout << endl << "Unable to open input file" << fileName << endl;
}
graph_size = 0;
while(getline(fin,fileName))
{
for(int i = 0; i < 3; i++)
{
fin >> matrix[graph_size][i];
cout << "graph: " << graph_size << " i: " << i << " " << matrix[graph_size][i] << endl;
}
//cout << graph_size << endl;
graph_size++;
}
}
#endif //KEY_H