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; 

  1. you don't have read commas in text file.
  2. also , instead of while (myfile.good()), use while ( myfile >> ...).
std::map<int, int> mymap;  char dummy; int a, b; while (myfile >> >> dummy >> b) {    mymap[a] = b; } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -