c++ - std::wofstream << WCHAR 和 << CHAR 可以同时吗?
问题描述
我们如何同时将 WCHAR 和 CHAR 写入 wofstream?像这样:
wofstream << L"汉字" << "汉字"
这是用于测试的东西。我只能“wofstream<<WCHAR”或“wofstream<<CHAR”,但不能同时“wofstream<<WCHAR<<CHAR”。
#include <iostream>
#include <fstream>
#include <locale>
int main() {
std::wofstream wof2;
wof2.open(L"2.txt", std::wofstream::app);
wof2 << "\nCHAR 汉";
wof2.flush();
wof2 << L"\nWCHAR 汉";
wof2.close();
const char * tmp = setlocale(LC_ALL, "");
std::cout << tmp << std::endl;
std::locale::global(std::locale(""));
wof2.open(L"2.txt", std::wofstream::app);
wof2.imbue(std::locale());
wof2 << L"\nWCHAR after imbue";
wof2.flush();
wof2 << L"\nWCHAR 汉";
wof2.flush();
wof2 << "\nCHAR汉";
wof2.flush();
return 0;
}
我们可以在控制台看到
Chinese (Simplified)_China.936
但是在 2.txt 中,我看到了
CHAR 汉
WCHAR
WCHAR after imbue
WCHAR 汉
CHAR
解决方案
推荐阅读
- pytorch - 如何找到 torch.nn.conv_transpose2d 和 max_unpool2d 的参数?
- java - docker中的内存使用超过了xmx控制或小于xms
- javascript - momentjs 不会按照指定的时区更改日期/时间
- c# - 身份确认电子邮件问题
- unity3d - Unity - 球弹跳
- java - 在 vscode 中运行 Java:“构建失败,要继续吗?” 如果我选择“继续”,它工作正常
- vue.js - 在 vuepress 中,如何将一些 md 内容动态呈现为客户主题(vue 模板)
- powershell - 如何让powershell等待批处理文件完成远程服务器上所有命令的执行
- c# - 来自鼠标单击事件的多个正确 If 语句
- guice - 我可以在不扩展 AbstractModule 的类中有一个 Guice @Provides 方法吗?