我在win32应用程序中使用easylogging++做日志,字符集使用的是Unicode,默认无法输出中文到日志,看了http://blog.csdn.net/Fish_55_66/article/details/49451321中的介绍,试着用
-
#define ELPP_UNICODE
-
#include "easylogging++.h"
-
-
INITIALIZE_EASYLOGGINGPP
-
-
int
main(
int
argc,
char
** argv)
-
{
-
-
START_EASYLOGGINGPP(argc, argv);
-
-
LOG(INFO) << L
"宏定义演示。"
;
-
-
system(
"pause"
);
-
return
0;
结果编译器链接的时候报错:
1>tijianji.obj : error LNK2001: 无法解析的外部符号 "public: virtual class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __thiscall el::base::DefaultLogBuilder::build(class el::LogMessage const *,bool)const " (?build@DefaultLogBuilder@base@el@@UBE?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PBVLogMessage@3@_N@Z)
1>E:\__wang\workspace\Projects\tijianji\Debug\tijianji.exe : fatal error LNK1120: 1 个无法解析的外部命令
是宏INITIALIZE_EASYLOGGINGPP里面的class DefaultLogBuilder : public LogBuilder {
public:
base::type::string_t build(const LogMessage* logMessage, bool appendNewLine) const;
};引起的。报错应该是string_t无法识别引起的,这个类型声明是这样的:
#if defined(ELPP_UNICODE)
# define ELPP_LITERAL(txt) L##txt
# define ELPP_STRLEN wcslen
# if defined ELPP_CUSTOM_COUT
# define ELPP_COUT ELPP_CUSTOM_COUT
# else
# define ELPP_COUT std::wcout
# endif // defined ELPP_CUSTOM_COUT
typedef wchar_t char_t;
typedef std::wstring string_t;
typedef std::wstringstream stringstream_t;
typedef std::wfstream fstream_t;
typedef std::wostream ostream_t;
#else
# define ELPP_LITERAL(txt) txt
# define ELPP_STRLEN strlen
# if defined ELPP_CUSTOM_COUT
# define ELPP_COUT ELPP_CUSTOM_COUT
# else
# define ELPP_COUT std::cout
# endif // defined ELPP_CUSTOM_COUT
typedef char char_t;
typedef std::string string_t;
typedef std::stringstream stringstream_t;
typedef std::fstream fstream_t;
typedef std::ostream ostream_t;
#endif // defined(ELPP_UNICODE)
我明明都定义了宏
#define ELPP_UNICODE为什么还是无法解析?
最后灵机一动把ELPP_UNICODE添加到“预处理器定义”里面,结果就链接通过了。
我在win32应用程序中使用easylogging++做日志,字符集使用的是Unicode,默认无法输出中文到日志,看了http://blog.csdn.net/Fish_55_66/article/details/49451321中的介绍,试着用#define ELPP_UNICODE #include "easylogging++.h" INITIALIZE_E
今天用MFC创建一个对话框程序并
使用
Easy
logg
in
g++
做日志输出,当程序
中
用TRACE打印信息时候,编译时候会报“
er
ror C3861: “TRACE”: 找不到标识符”,TRACE是MFC的宏,怎么可能出现这样的错误?经过反复注释代码发现是包含
Easy
logg
in
g++
后才会出现这个错误,那么
Easy
logg
ing做了什么?直接去看它的源码发现有这么写的
// Undef level
可以
使用
Python的内置函数chr()将
Unicode
编码转换为对应的
中
文字符。例如,要将
Unicode
编码为U+4E2D转换为
中
文字符,可以
使用
以下代码:
print(chr(x4E2D))
输出结果为:
中
注意,这里的x4E2D是U+4E2D的十六进制表示。如果你有一个
Unicode
编码的字符串,可以
使用
Python的内置函数ord()将其转换为对应的整数值,然后再
使用
chr()函数将其转换为
中
文字符。例如:
s = '\u4E2D\u6587'
print(chr(int(s[2:6], 16)), chr(int(s[6:10], 16)))
输出结果为:
中
文