我知道这听起来很愚蠢,但我在 Windows7 上使用 MinGW32,并且“to_string
未在此范围内声明。” It's an actual GCC Bug , 我关注了 these instructions他们没有工作。那么,如何在不使用 to_string
或 stoi
的情况下将 int 转换为 C++11 中的字符串? (另外,我启用了 -std=c++11
标志)。
最佳答案
这不是最快的方法,但您可以这样做:
#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';
}
关于c++ - 如何在不使用 to_string 或 stoi 的情况下将 int 转换为 C++11 中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30973994/