解决编译C++程序时to_string()未声明等相关问题

#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    int sum = 0;
    string str[10] =  {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
    for (int i = 0; i < s.length(); i++)
        sum += (s[i] - '0');
    string num = to_string(sum);
    for (int i = 0; i < num.length(); i++) {
        if (i != 0) cout << " ";
        cout << str[num[i] - '0'];
    }
    return 0;
}

当用dev c++编译时会报 [Error] 'to_string' was not declared in this scope

当用code::Blocks编译时会报   to_string' was not declared in this scope

原因一样,均是因为编译器不支持C++11标准,所以解决方法就是使其能够支持该标准。

具体解决方案如下:

对于dev-C++

tool-Compiler Options

勾选Add the following commands when calling the comoiler选项,然后在输入框中输入:-std=c++11。即可!

对于Code::Blocks

setting-compiler

如图,勾选C++11标准即可!

 

  • 17
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值