错误:"stoi"未在此范围内声明(代码::Windows 10 上的块 16.01)

error: 'stoi' was not declared in this scope (Code::Blocks 16.01 on Windows 10)

本文关键字:Windows stoi 范围内 错误 声明 代码      更新时间:2023-10-16

我得到错误:"stoi"未在此范围中声明。

#include <string>
using namespace std;
...
int x;
x = stoi(arg[0]);

我在Windows 10上运行代码::块16.01,设置为-std=c++11。

我在这个页面上找不到任何有用的信息:未在此范围中声明"stoi">

我在某个地方看到升级gcc可以解决这个问题,但我在页面上没有找到合适的安装:https://mingw-w64.org/doku.php/download

同样的代码在Linux Mint 17.3上的code::Blocks 13.12中运行良好。

是否有针对此问题的建议修复程序?这可以通过使用64位版本的MinGW来修复吗(假设它与Code::Blocks 16.01兼容)?

更新有一个变通方法,使用atoi和c_str代替:

x = atoi(arg[0].c_str());

我认为这是MinGW的一个错误。有关更多信息,请查看这篇StackOverflow文章。特别是DRH的回答。