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

标签 c++ string c++11 gcc

我知道这听起来很愚蠢,但我在 Windows7 上使用 MinGW32,并且“to_string 未在此范围内声明。” It's an actual GCC Bug , 我关注了 these instructions他们没有工作。那么,如何在不使用 to_stringstoi 的情况下将 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/

相关文章:

类内的 c++ 全局 map ,不打印 map 元素。使用 cmake

c - C 中的结构和指针

php - 如何在php中从数据库中的数组中添加多行

c++ - 修复警告 "comparison is always false due to limited range of data type [-Wtype-limits]"

c++ - 指向函数成员的已删除指针的类型

c++ - 使用 WriteFile/ReadFile 进行串行通信

c++ - 调用 `list<T>::end()` 不是很低效吗?

c++ - 如何在c/c++中实现挂载功能

c - 获取文本而不是 EOF

c++ - 我可以通过它的字节指定一个整数常量吗?