gpt4 book ai didi

c++ - 如何使用 win32 编写通用警报消息?

转载 作者:行者123 更新时间:2023-11-30 02:12:45 25 4
gpt4 key购买 nike

我只是想将下面的这个方法扩展成更通用的东西,它应该接受任何类型的参数并使用 MessageBox() 显示它:

void alert(char *item)
{
MessageBox(NULL, item, "Message", MB_OK | MB_ICONINFORMATION);
}

有人能帮忙吗?

最佳答案

#include <sstream>
template<typename T>
void alert(T item)
{
//this accepts all types that supports operator <<
std::ostringstream os;
os << item;
MessageBoxA(NULL, os.str().c_str(), "Message", MB_OK | MB_ICONINFORMATION);
}

//now you need specialization for wide char
void alert(const wchar_t* item)
{

MessageBoxW(NULL, item, "Message", MB_OK | MB_ICONINFORMATION);
}

关于c++ - 如何使用 win32 编写通用警报消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1394053/

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