【发布时间】:2016-01-03 20:10:29
【问题描述】:
如何使用 std::wfstream 将波斯语文本(如“خلیج فارس”)写入文件?
我尝试了以下代码,但它不起作用。
#include <iostream>
#include <string>
#include <fstream>
int main()
{
std::wfstream f("D:\\test.txt", std::ios::out);
std::wstring s1(L"خلیج فارس");
f << s1.c_str();
f.close();
return 0;
}
运行程序后文件为空。
【问题讨论】:
-
我检查了输出文件,它是空的
-
f.imbue(std::locale(""));如果波斯语是您的默认系统区域设置 (stackoverflow.com/a/2169088/1566267) -
必须是 std::wfstream 还是也允许 std::fstream?
-
@robsn:是的,正如在
ios_base中声明的那样。 -
指定您的平台 - Windows、Linux、Mac?在某些操作系统上,控制台是 Unicode 友好的,在某些操作系统上 - 不是那么多。
标签: c++ string unicode persian farsi