[英]Getting ifstream to read ints from a file into a map C++
我似乎無法讓我的文件“ paths.txt”讀入我的地圖文件。 我無法弄清楚我在做什么錯。 我將不勝感激任何指針。 我想要的最終結果是將每個鍵值對帶入映射。
我文件的格式是
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
我的代碼是
ifstream myfile("paths.txt");
std::map<int, int> mymap;
int a, b;
while (myfile.good())
{
myfile >> a >> b;
mymap[a] = b;
}
mymap;
while ( myfile >> ...)
代替while (myfile.good())
while ( myfile >> ...)
。 std::map<int, int> mymap;
char dummy;
int a, b;
while (myfile >> a >> dummy >> b)
{
mymap[a] = b;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.