我找到了一个我正在尝试实现的类似示例:
std::unordered_map<std::string,std::string> mymap = {
{"us","United States"},
{"uk","United Kingdom"},
{"fr","France"},
{"de","Germany"}
};
但是,我拥有的值位于 CSV 文件中。
我是否需要将这些值插入到不同的容器中,然后将它们添加到 unordered_map 或者是否可以直接从文件中添加它们?
我正在努力弄清楚,所以目前我只是将文件内容写到屏幕上:
int menuLoop = 1;
int userChoice;
string getInput;
while(menuLoop == 1)
{
cout << "Menu\n\n"
<< "1. 20\n"
<< "2. 100\n"
<< "3. 500\n"
<< "4. 1000\n"
<< "5. 10,000\n"
<< "6. 50,000\n\n";
cin >> userChoice;
if(userChoice == 1)
{
cout << "\n20\n\n";
string getContent;
ifstream openFile("20.txt");
if(openFile.is_open())
{
while(!openFile.eof())
{
getline(openFile, getContent);
cout << getContent << endl;
}
}
system("PAUSE");
}
}
文件内容:
Bpgvjdfj,Bvfbyfzc
Zjmvxouu,Fsmotsaa
Xocbwmnd,Fcdlnmhb
Fsmotsaa,Zexyegma
Bvfbyfzc,Qkignteu
Uysmwjdb,Wzujllbk
Fwhbryyz,Byoifnrp
Klqljfrk,Bpgvjdfj
Qkignteu,Wgqtalnh
Wgqtalnh,Coyuhnbx
Sgtgyldw,Fwhbryyz
Coyuhnbx,Zjmvxouu
Zvjxfwkx,Sgtgyldw
Czeagvnj,Uysmwjdb
Oljgjisa,Dffkuztu
Zexyegma,Zvjxfwkx
Fcdlnmhb,Klqljfrk
Wzujllbk,Oljgjisa
Byoifnrp,Czeagvnj