My code is crashing upon reading from a file (seen at the end of this post). I am declaring an ifstream object in main, passing it through a buildGraph function (which takes ifstream& as a parameter), and attempting to pass the first token into a string temp.
Relevant code from main:
#include <fstream>
int main() {
ifstream infile1("data31.txt");
if (!infile1) {
cout << "File could not be opened." << endl;
return 1;
}
GraphM G;
G.buildGraph(infile1);
}
Relevant code from graphm.cpp:
#include <fstream>
#include <string>
void GraphM::buildGraph(ifstream& input)
{
string temp;
input >> temp;
}
There is a header file graphm.h that includes fstream as well. I talked with a couple of tutors who work at the college I'm at and they haven't been able to help at all, as they are as confused as I am. The function getline() throws a segmentation fault, as well, so that won't work. What am I doing wrong, here?
Also, the .txt I'm reading from:
5
Aurora and 85th
Green Lake Starbucks
Woodland Park Zoo
Troll under bridge
PCC
1 2 50
1 3 20
1 5 30
2 4 10
3 2 20
3 4 40
5 2 20
5 4 25
0 0 0
3
aaa
bbb
ccc
1 2 10
1 3 5
2 3 20
3 2 4
0 0 0