我有一个 IPA 的列表(UTF-8) 符号在名为 ipa.txt 的文本文件中,并为其分配了数字。我如何将它与源文件交叉引用,该源文件也是一个包含一堆单词及其相应 IPA 的文本文件,以返回每个名称的文本文件,其名称作为文件名,文本文件中应包含相应的文本文件IPA 的数量。
下面是我试过但没有用的,只有输出大部分是 000000。
int main()
{
std::unordered_map <wchar_t, int> map;
std::wifstream file;
file.open("ipa.txt");
if (file.is_open()) {
std::cout << "opened ipa file";
}
wchar_t from;
int to;
while (file >> from >> to) {
map.insert(std::make_pair(from, to));
}
std::wifstream outfile;
outfile.open("source.txt");
if (outfile.is_open()) {
std::cout << "opened source file";
}
std::wstring id;
std::wstring name;
while (outfile >> id >> name) {
std::ofstream outputfile;
outputfile.open(id + L".txt");
for (wchar_t c : name) outputfile << map[c];
}
system("pause");
return 0;
}
最佳答案
我相信您在 name
的迭代中使用了错误的 c
类型。由于 c
用作映射的键,而 name
是 wstring
,您应该使用:
for (wchar_t c : name) outputfile << map[c];
代替:
for (char c : name) outputfile << map[c];
不是吗?
希望这会有所帮助,Stefano
关于c++ - 如何在 C++ 中读取 UTF-8 文件数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44549101/