cout a string gets the address instead of value(cout 字符串获取地址而不是值)
本文介绍了cout 字符串获取地址而不是值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个宏定义如下:
#ifdef UNICODE
typedef wchar_t TCHAR;
#define TEXT(quote) L##quote
#else
typedef char TCHAR;
#define TEXT(quote) quote
#endif
当我尝试使用 std::cout 打印消息时,如下所示:
When I try to print a message using std::cout as below:
TCHAR* test = TEXT("test");
cout << test;
我得到的地址是 00D82110 而不是值test".
What I get the address such as 00D82110 instead of the value "test".
任何人都可以提出任何建议,我如何在此处打印值?非常感谢!
Can anybody give any suggestion how can I print the value here? Thanks a lot!
推荐答案
对于宽字符,您需要使用 wcout
而不是 cout
.这样做:
You need to use wcout
instead of cout
for wide characters. Do this:
#ifdef UNICODE
typedef wchar_t TCHAR;
#define TEXT(quote) L##quote
#define COUT wcout
#else
typedef char TCHAR;
#define TEXT(quote) quote
#define COUT cout
#endif
然后:
TCHAR* test = TEXT("test");
COUT << test;
这篇关于cout 字符串获取地址而不是值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:cout 字符串获取地址而不是值


基础教程推荐
猜你喜欢
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01