如何使用MinGW在C ++中将int转换为std :: string? [英] How do I convert int to std::string in C++ with MinGW?

查看:144
本文介绍了如何使用MinGW在C ++中将int转换为std :: string?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个已知问题,std :: to_string不起作用.甚至std :: itoa都不适合我.如何将int转换为字符串?我不太在乎性能,我所需要的只是在不太慢的情况下工作.

It is a known issue that std::to_string does not work. Even std::itoa didn't work for me. What can I do to convert an int to a string? I don't care much about performance, all I need it is to work without being too slow.

我已经安装了最新的mingw 32,std :: to_string仍然不起作用.我从这里安装它:

I have the latest mingw 32 installed, std::to_string still does not work. I installed it from here: http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/32-bit/threads-win32/sjlj/

推荐答案

您是否考虑过使用字符串流?

Have you considered using a stringstream?

#include <sstream>

std::string itos(int i){
    std::stringstream ss;
    ss<<i;
    return ss.str();
}

这篇关于如何使用MinGW在C ++中将int转换为std :: string?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆