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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -