'stoi'和'to_string'不是'std'的成员, [英] 'stoi' and 'to_string' is not a member of 'std'

查看:855
本文介绍了'stoi'和'to_string'不是'std'的成员,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,它相当大,所以我只是在这里创建一个快照:

  int l = 3; 
vector< int>权重;

void changeWeights(int out){
for(int i = 0; i int w = std :: stoi std :: to_string(weights [i])) -
out * std :: stoi(std :: to_string(weights [i]));
if(w <-l){
w = -l;
} else if(w> l){
w = 1;
}
weights.assign(i,w);
}
}



我在'stoi' to_string'以

形式的函数调用

  Main.cpp:35:21:error:'stoi' 'std'
int w = std :: stoi(std :: to_string(weights [i])) -
^
Main.cpp:35:31:error:'to_string'is不是'std'的成员
int w = std :: stoi(std :: to_string(weights [i])) -
^
Main.cpp:36:17: 'stoi'不是'std'的成员
out * std :: stoi(std :: to_string(weights [i]));
^
Main.cpp:36:27:error:'to_string'不是'std'的成员
out * std :: stoi(std :: to_string(weights [i] ));

我已经读了一些类似的查询,答案是在-std = c ++ 11中添加, -std = c ++ 0x当编译 - 这两个解决方案都不工作。另一个解决方案建议在编译器版本中的错误,但它不是我使用的编译器我不认为。我在64x Apple Macbook Pro上使用g ++(GCC)5.0.0 20141005(实验版)。



感谢任何帮助。

解决方案

使用 stoi() to_string()在这部分代码是很奇怪,而且完全不必要。你可以简单地写

  int w = weights [i]  -  out * weights [i] 






要使用 std :: stoi() std :: to_string() 您需要有正确的

  #include< string> ; 

语句和c ++ 11语言选项集(请参阅上述文档参考的链接) 。


I have some code, it's quite large so I'll just create a snapshot of it here:

    int l = 3;
    vector<int> weights;   

    void changeWeights(int out){
    for (int i = 0; i < weights.size(); i++){
        int w = std::stoi(std::to_string(weights[i])) -
        out*std::stoi(std::to_string(weights[i]));
        if (w < -l){
          w = -l;
        } else if(w > l){
            w = l;
        }
        weights.assign(i, w);
    }
}

I get errors on both the 'stoi' and 'to_string' function calls in the form of

Main.cpp:35:21: error: ‘stoi’ is not a member of ‘std’
         int w = std::stoi(std::to_string(weights[i])) -
                 ^
Main.cpp:35:31: error: ‘to_string’ is not a member of ‘std’
         int w = std::stoi(std::to_string(weights[i])) -
                           ^
Main.cpp:36:17: error: ‘stoi’ is not a member of ‘std’
         out*std::stoi(std::to_string(weights[i]));
             ^
Main.cpp:36:27: error: ‘to_string’ is not a member of ‘std’
         out*std::stoi(std::to_string(weights[i]));

I have read some similar queries whereby the answer was to add in -std=c++11 or -std=c++0x when compiling - both these solutions did not work. Another solution suggested a bug in the compiler version but it's not the compiler I am using I do not think. I am using g++ (GCC) 5.0.0 20141005 (experimental) version on a 64x Apple Macbook Pro.

Thanks for any help.

解决方案

Usage of stoi() and to_string() in this part of code is pretty weird, and completely unnecessary. You can simply write

int w = weights[i] - out * weights[i];


To use std::stoi() and std::to_string() you need to have a proper

#include <string>

statement, and the c++11 language options set (see the links to the documentation reference above).

这篇关于'stoi'和'to_string'不是'std'的成员,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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