dictionary - Getting ifstream to read ints from a file into a map C++ -
i cannot seem file "paths.txt" read map file. cannot figure out doing wrong. i'd appreciate pointers. end result want take each of key value pairs map.
the format of file
192, 16 120, 134 256, 87 122, 167 142, 97 157, 130 245, 232 223, 63 107, 217 36, 63 206, 179 246, 8 91, 178
and code
ifstream myfile("paths.txt"); std::map<int, int> mymap; int a, b; while (myfile.good()) { myfile >> >> b; mymap[a] = b; } mymap;
- you don't have read commas in text file.
- also , instead of
while (myfile.good())
, usewhile ( myfile >> ...)
.
std::map<int, int> mymap; char dummy; int a, b; while (myfile >> >> dummy >> b) { mymap[a] = b; }
Comments
Post a Comment