当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 使用ofstream输出unicode

使用ofstream输出unicode

2019年02月21日  | 移动技术网IT编程  | 我要评论

黄粉虫养殖技术,潘道津,寇振海老婆李婷

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();
}

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网