cout a string gets the address instead of value(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 字符串获取地址而不是值


- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01