std :: stoi的问题,不工作在MinGW GCC 4.7.2 [英] Problems with std::stoi, not working on MinGW GCC 4.7.2

查看:371
本文介绍了std :: stoi的问题,不工作在MinGW GCC 4.7.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
#include <string>

int main()
{
    std::string test = "45";
    int myint = stoi(test);
    std::cout << myint << '\n';
}

我在运行MinGW GCC 4.7.2的计算机上试过这个代码。它给我这个错误:

I tried this code on my computer which is running MinGW GCC 4.7.2. It gives me this error:

我做错了,我从 cppreference 。它的完全相同的代码。它与此处

What am I doing wrong, I got this from cppreference. Its the exact same code. And its a different error from the one described here.

推荐答案

看来你的MinGW需要一个补丁:在MinGW中启用字符串转换函数

It seems your MinGW needs a patch: Enabling string conversion functions in MinGW


此修补程序启用以下列表std命名空间中的C ++ 11函数和模板

This patch enables the following list of C++11 functions and templates in the std namespace:

stoi,stol,stoul,stoll,stof,stod,stold,
to_string ,to_wstring

stoi, stol, stoul, stoll, stof, stod, stold, to_string, to_wstring

在上面的链接中,有一个 .zip 它和

In above link, there is a .zip file, download it and


  • 将wchar.h和stdio.h从zip文件
    中的include目录复制到以下目录):C:\mingw \include(用适当的目录替换
    C:\mingw \)

  • 将os_defines.h复制到以下目录:
    C:\mingw\lib\gcc\mingw32\4.7.0\include\c ++ \mingw32\bits(replace
    C:\mingw\ with适当的目录)(用
    替换4.7.0正确的版本号)

这篇关于std :: stoi的问题,不工作在MinGW GCC 4.7.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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