I'm trying to bring data from .txt file for my program that makes edge adjacency list using C++, but it didn't work the way I wanted. I don't have good knowledge in regards to delimiters of ifstream >> function.
I know that ifstream >> ignores line segments and reads the next value, but I'm not sure if it also ignores spaces.
int numVert;
int numEdge;
int src, dest, weight;
ifstream myFile("Ginput.txt");
myFile >> numVert;
myFile >> numEdge;
graph = createGraph(numVert);
for (int i = 0; i <= numEdge*3; i++)
{
myFile >> src;
myFile >> dest;
myFile >> weight;
addEdge(graph, src, dest, weight);
}
The .txt file format is like this:
3 6
1 4 2
2 4 6
2 3 2
1 2 3
2 5 6
2 1 5
1 4 3
The first 2 integers are for number of vertices and number of edges, respectively.
The first digit, after the first line, is the source, second digit is destination, and third digit is weight.
What it should do is to distinguish between lines and spaces, and input the integers into correct data. So, it should be:
numVert = 3;
numEdge = 6;
First line: src = 1, dest = 4, weight = 2
Second line: src = 2, dest = 4, weight = 6
and so on.
Please help me out. Thank you.