使用ofstream输出unicode
2024-10-19 13:31:03
void saveWideFileHead(std::ofstream& out)// 写入文件内容前,先写入BOM
{
char const* const utf16head = "\xFF\xFE";
out.write(utf16head, 2);
} void saveWideFileContent(std::ofstream& out, wchar_t const* str, int size)
{
char const* pos = (char const*)str;
out.write(pos, size);
} void saveWideFileCRLF(std::ofstream& out)// 写入回车换行符
{
char const* const utf16head = "\x0D\x00\x0A\x00";
out.write(utf16head, 4);
} void Test()
{
std::ofstream of("test.log", std::ios::binary | std::ios::out);
saveWideFileHead(of);
CString str("hello中国world1234");
saveWideFileContent(of, str, str.GetLength() * 2);
saveWideFileCRLF(of);
saveWideFileContent(of, str, str.GetLength() * 2);
of.close();
}
最新文章
- sql server报:名称 不是有效的标识符
- sql编程(四)触发器
- WinStore之Application Data
- Spring-事物配置
- CF 161D Distance in Tree 树形DP
- CAT XQX --- 省市三级级联实现说明
- <;亲测好使>;mac os 安装mcrypt扩展
- Android Service 的一些笔记
- Linux趣谈
- 重写equals()与hashCode()方法
- R.layout.main connot be resolved 和R.java消失
- SQL Server Alwayson读写分离配置
- hdu4416 Good Article Good sentence (后缀数组)
- python入门:python包管理工具pip的安装
- C# 给现有PDF文档添加页眉、页脚
- Codeforces 1096F(dp + 树状数组)
- spring-boot (三) spring data jpa
- Hiho #1075: 开锁魔法III
- Java之路(三) 控制执行流程
- MyBatis各种类型的入参使用方式