gpt4 book ai didi

c++ - std::cout 在屏幕上显示十六进制而不是文本

转载 作者:太空宇宙 更新时间:2023-11-04 15:21:28 25 4
gpt4 key购买 nike

我得到这样的系统时间:

time_t t = time(0); 
struct tm* now = localtime(&t);
TCHAR* tInfo = new TCHAR[256];
swprintf_s(tInfo
, 256
, _T("Current time: %i:%i:%i")
, now->tm_hour
, now->tm_min
, now->tm_sec);

然后在屏幕上显示:

std::cout << tInfo << std::endl; 

但是 当前时间:12:57:56 我在屏幕上得到了:0x001967a8。我做错了什么?

最佳答案

您正在尝试打印“宽”字符串。你需要使用:

std::wcout << tInfo << std::endl;

“窄”版本 cout 不知道“宽”字符,因此只会打印地址,就像您尝试打印其他随机指针类型一样。

关于c++ - std::cout 在屏幕上显示十六进制而不是文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18099058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com