CSV Parser works in windows, not linux.
- by ladookie
I'm parsing a CSV file that looks like this:
E1,E2,E7,E8,,,
E2,E1,E3,,,,
E3,E2,E8,,,
E4,E5,E8,E11,,,
I store the first entry in each line in a string, and the rest go in a vector of strings:
while (getline(file_input, line)) {
stringstream tokenizer;
tokenizer << line;
getline(tokenizer, roomID, ',');
vector<string> aVector;
while (getline(tokenizer, adjRoomID, ',')) {
if (!adjRoomID.empty()) {
aVector.push_back(adjRoomID);
}
}
Room aRoom(roomID, aVector);
rooms.addToTail(aRoom);
}
In windows this works fine, however in Linux the first entry of each vector mysteriously loses the first character. For Example in the first iteration through the while loop:
roomID would be E1 and aVector would be 2 E7 E8
then the second iteration:
roomID would be E2 and aVector would be 1 E3
Notice the missing E's in the first entry of aVector.
when I put in some debugging code it appears that it is initially being stored correctly in the vector, but then something overwrites it. Kudos to whoever figures this one out. Seems bizarre to me.
rooms is declared as such:
DLList<Room> rooms where DLList stands for Doubly-Linked list.