我有一些代码,它非常大,所以我只是在这里创建一个快照:
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);
}
}
我在&#39; stoi&#39;和&#39; to_string&#39;函数调用以
的形式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]));
我已经阅读了一些类似的查询,其中答案是在编译时添加-std = c ++ 11或-std = c ++ 0x - 这两种解决方案都不起作用。另一个解决方案提出了编译器版本中的一个错误,但它不是我正在使用的编译器,我不认为。我在64x Apple Macbook Pro上使用g ++(GCC)5.0.0 20141005(实验版)。
答案 0 :(得分:4)
在这部分代码中使用stoi()
和to_string()
非常奇怪,完全没必要。你可以简单地写
int w = weights[i] - out * weights[i];
要使用std::stoi()
和std::to_string()
,您需要有正确的
#include <string>
语句和c ++ 11语言选项集(请参阅上面文档参考的链接)。