如何在不使用to_string或stoi的情况下将int转换为C++ 11中的字符串?

Eri*_*ans 5 c++ string gcc c++11

我知道这听起来很愚蠢,但我在Windows7上使用MinGW32,并且" to_string未在此范围内声明." 这是一个真正的GCC Bug,我已经按照这些说明进行操作了.那么,如何在不使用to_stringstoi?的情况下将int转换为C++ 11中的字符串?(另外,我-std=c++11启用了标志).

Gal*_*lik 7

它不是最快的方法,但你可以这样做:

#include <string>
#include <sstream>
#include <iostream>

template<typename ValueType>
std::string stringulate(ValueType v)
{
    std::ostringstream oss;
    oss << v;
    return oss.str();
}

int main()
{
    std::cout << ("string value: " + stringulate(5.98)) << '\n';
}
Run Code Online (Sandbox Code Playgroud)