我有一个清单IPA https://en.wikipedia.org/wiki/International_Phonetic_Alphabet名为 ipa.txt 的文本文件中的 (UTF-8) 符号并为其分配了数字。如何将它与源文件交叉引用,该源文件也是一个包含一堆单词及其相应的 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;
}
我相信您使用了错误的类型c
在迭代中使用name
. As c
用作地图的键,并且name
is a wstring
,你应该使用:
for (wchar_t c : name) outputfile << map[c];
代替:
for (char c : name) outputfile << map[c];
不是吗?
希望这会有所帮助,斯特凡诺
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)