Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 要调试的输出浮点_C++_C_Visual Studio - Fatal编程技术网

C++ 要调试的输出浮点

C++ 要调试的输出浮点,c++,c,visual-studio,C++,C,Visual Studio,我想知道是否有一种替代OutputDebugString的方法,而不是浮点数?我希望能够在Visual studio的输出中查看值。首先将浮点值转换为字符串 std::ostringstream ss; ss << 2.5; std::string s(ss.str()); 可选地,您可以使用跳过中间字符串 OutputDebugString(ss.str().c_str()); 我把埃里克的答案和托兰·比卢普斯的答案结合起来 要获得: std::wstring d2ws(双值)

我想知道是否有一种替代OutputDebugString的方法,而不是浮点数?我希望能够在Visual studio的输出中查看值。

首先将浮点值转换为字符串

std::ostringstream ss;
ss << 2.5;
std::string s(ss.str());
可选地,您可以使用跳过中间字符串

OutputDebugString(ss.str().c_str());
我把埃里克的答案和托兰·比卢普斯的答案结合起来 要获得:

std::wstring d2ws(双值){
返回s2ws(d2s(值));
}
std::字符串d2s(双值){
std::ostringstream oss;

oss那么你可以wsprintf float到一个缓冲区并输出DebugString,但是OutputDebugString()不接受[const char*]作为输入!它需要先转换为LPCWSTR。嗯…有
std::wostringstream
已经全部完成了。我不知道。谢谢。
OutputDebugString(ss.str().c_str());
std::wstring d2ws(double value) {
    return s2ws(d2s(value));
}

std::string d2s(double value) {
    std::ostringstream oss;
    oss << value;
    return oss.str();
}

std::wstring s2ws(const std::string& s)
{
    int len;
    int slength = (int)s.length() + 1;
    len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
    wchar_t* buf = new wchar_t[len];
    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
    std::wstring r(buf);
    delete[] buf;
    return r;
}

double theValue=2.5;
OutputDebugString(d2ws(theValue).c_str());
std::wstring d2ws(double value) {
    std::wostringstream woss;
    woss << value;
    return woss.str();
}

double theValue=2.5;
OutputDebugString(d2ws(theValue).c_str());