繁体   English   中英

C ++浮动到const wchar_t *转换函数

[英]c++ float to const wchar_t* converting function

我正在将浮点数转换为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()代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM