. 自山海来 2021-05-05 14:08 采纳率: 100%
浏览 133
已采纳

stoi 包含了头文件什么还是示错?

这串代码在做题页面可运行,提交上去也是正确的,但是在vc++和codeblocks上就会显示出这个错误。

[b][Error] 'stoi' was not declared in this scope[/b]

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
   string str;
   int year;
   int month;
   cin >> str;
   if (str.size() == 6)
   {
       year = stoi(str.substr(0,4));
       month = stoi(str.substr(4));
   }
   else
   {
       year = stoi(str.substr(0,2));
       month = stoi(str.substr(2));
       if(year < 22)  year += 2000;
       else year += 1900;
   }
   printf("%04d-%02d",year,month);
   return 0;
}

 

  • 写回答

4条回答 默认 最新

  • 小兔子编程 优质创作者: 编程框架技术领域 2021-05-05 14:52
    关注

     

    解决办法:然后在“编译选项”里,选择 语言标准为"ISO C++11"标准即可

    再点"代码生成/优化",再点"代码生成",再点"语言标准",选择"ISO C++11"标准,点击确认即可。

     

    如果上面还解决不了,可以把你的版本换成 dev c++ 5.11,在设置即可

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?