栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++11 多国语言字符串处理

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++11 多国语言字符串处理

c++11 多国语言字符串处理方案

文本编码格式限定uft-8

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;


// utf8格式string转wstring
static std::wstring stringtowstring(const std::string& input)
{
	std::wstring_convert> converter;
	return converter.from_bytes(input);
}
// wstring转utf8格式string
static std::string wstringtostring(const std::wstring& input)
{
	//std::wstring_convert> converter;
	std::wstring_convert> converter;
	return converter.to_bytes(input);
}

// 获取当前时间戳
static int64_t C11GetTimeStamp()
{
	std::chrono::time_point tp = std::chrono::time_point_cast(std::chrono::system_clock::now());
	auto tmp = std::chrono::duration_cast(tp.time_since_epoch());
	return tmp.count();

}

// 文本输出文件名
std::string fileName = "log.txt";

// 输出打印
void LOG_DF(const std::wstring& mlog)
{
	// wstring转换函数
	string utf8 = wstringtostring(mlog);
	// 打印
	std::locale::global(std::locale("C"));
	std::cout << utf8 << std::endl;
	std::locale::global(std::locale(""));
	// 写入文件
	std::ofstream log_f(fileName, std::ios_base::app);
	log_f << utf8 << std::endl;
	log_f.close();
}

// LOG_D接口
#define LOG_D(log) {
	if(1){
		std::wstringstream ss;
		ss < 

打印输出:

[1,653,288,712,474][] 这是一个测试,Это тест.これはテストです,this is a test, Das ist ein Test.ÌÌß水406 [/home/hyd/projects/ConsoleApplication1/main.cpp:78]
[1,653,288,712,474][] 演讲的名字。название лекции.スピーチの名前。The names for the discourse.Die bezeichnungen für den diskurs.ÌÌß水406 [/home/hyd/projects/ConsoleApplication1/main.cpp:80]
[1,653,288,712,475][] 演讲的名字。название лекции.スピーチの名前。The names for the discourse.Die bezeichnungen für den diskurs.ÌÌß水hydthis a test127.0.0.1:2368 [/home/hyd/projects/ConsoleApplication1/main.cpp:82]

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/925963.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号