【发布时间】:2018-09-29 03:39:17
【问题描述】:
我想使用纯文本文件来保存来自用户的输入,以便稍后读出。在应用程序中,可能会出现德语和西班牙语的特殊符号。不幸的是,下面的代码没有将标志正确地保存在文件中。如何最好地解决这个问题?
我在 C 中的一个类似应用程序中通过保存在 .bin 文件而不是 .txt 中解决了这个问题,但是在 c++ 中没有更好的解决方案吗?
#include <string>
#include <fstream>
#include <iostream>
int main() {
std::string s = "abcöäüÑ"; //(alt + 165 for Ñ)
std::ofstream ofs{ "test.txt" };
ofs << s <<'\n'; //this works fine "abcöäüÑ"
std::string s2;
std::cin >> s2; //typeing in the app abcöäüÑ (alt+165 for Ñ)
// i use a windows system with a german keyboard setting
ofs << s2 <<'\n'; //this doesn't it gets "abc”„¥"
}
我使用带有德语键盘设置的 Visual Studio 2017 的 windows 7 64 系统。
【问题讨论】:
标签: c++ windows visual-c++ unicode