gpt4 book ai didi

c++ float to const wchar_t* 转换函数

转载 作者:行者123 更新时间:2023-11-27 22:48:22 25 4
gpt4 key购买 nike

我正在将 float 转换为 const wchar_t *

DisplayText(ConversionUtils::FloatToWstring(fps).c_str()); // Prints garbage

DisplayText(std::to_wstring(fps).c_str()); // Doesn't print anything to the device.

有了这个功能:

std::wstring ConversionUtils::FloatToWstring(float value) {

return std::to_wstring(value);
}

我想得到这样的东西:

DisplayText(ConversionUtils::FloatToConstWcharPtr(fps));

最佳答案

按值返回:

std::wstring ConversionUtils::FloatToWchar(float value) {
std::string str = std::to_string(value);
return std::wstring(str.begin(), str.end());
}

或者更好的是,使用 std::to_wstring() 代替。

关于c++ float to const wchar_t* 转换函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40703869/

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