I'm attempting to build an adjacency matrix based on a an input file that lists for a graph. These edges are represented by two string names separated by a space. For example:
AB BC
CD DE
EF FG
I'm utilizing an STL Map container which has the name as the key and an integer that represents the name's index on the adjacency matrix. So:
AB: 0
BC: 1
DC: 2
etc.
I've parsed the information from the file into two string variables. These two strings appear to print correctly, and do not seem to have any extra characters. However, when I try to reference the parsed names via my map, only the second string (player2) returns the correct index number. Player1 always seems to return 0, no matter what the string value is.
Is there something I'm missing? The Map works correctly when tested outside of the following loop, and I've gotten the correct indexes when I reference all of the available names so I doubt it's an issue with the Map.
while(getline(inputFile,temp))
{
stringstream ss(temp);
getline(ss,player1,' ');
getline(ss,player2);
cout << map[player1] << map[player2};
}
Aucun commentaire:
Enregistrer un commentaire