简体   繁体   English

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

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

I'm converting a float to a const wchar_t * 我正在将浮点数转换为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.

with this function : 具有此功能:

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

    return std::to_wstring(value);
}

I want to get something like that : 我想得到这样的东西:

DisplayText(ConversionUtils::FloatToConstWcharPtr(fps));

Just return by value: 只需按值返回:

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

Or better, use std::to_wstring() instead. 或更好,使用std::to_wstring()代替。

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

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