这是关于文本输入文件中的 unicode 字符的问题。这个讨论很接近,但并不完全是答案。用 VS2008 编译并在 Windows 上执行这些字符在读取时被识别(可能表示为不同的符号但已读取) - 用 g++ 编译并在 linux 上执行它们显示为空白。
‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ‘ ’ “ ” • – — ˜ ™ š › œ ž Ÿ
其余的 Unicode 符号似乎工作正常,我没有检查它们,但发现这组不起作用。
问题:(1)为什么?(2) 有解决办法吗?
void Lexicon::buildMapFromFile(string filename ) //map
{
ifstream file;
file.open(filename.c_str(), ifstream::binary);
string wow, mem, key;
unsigned int x = 0;
while(true) {
getline(file, wow);
cout << wow << endl;
if (file.fail()) break; //boilerplate check for error
while (x < wow.length() ) {
if (wow[x] == ',') { //look for csv deliniator
key = mem;
mem.clear();
x++; //step over ','
} else
mem += wow[x++];
}
//cout << mem << " code " << key << " is " << (key[0] - '€') << " from €" << endl;
cout << "enter 1 to continue: ";
while (true) {
int choice = GetInteger();
if (choice == 1) break;
}
list_map0[key] = mem; //char to string
list_map1[mem] = key; //string to char
mem.clear(); //reset memory
x = 0;//reset index
}
//printf("%d\n", list_map0.size());
file.close();
}
unicode 符号从 csv 文件中读取并解析为 unicode 符号和关联的字符串。最初我虽然代码中有一个错误,但在这篇文章中,审查发现它很好,我关注了如何处理字符的问题。
测试是cout << wow << endl;