"stoi"和"to_string"不是"std"的成员
'stoi' and 'to_string' is not a member of 'std'
我有一些代码,它很大,所以我在这里创建一个快照:
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);
}
}
我在"stoi"和"to_string"函数调用中都收到错误,形式为
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(实验性(版本。
在
这部分代码中使用stoi()
和to_string()
是非常奇怪的,而且完全没有必要。你可以简单地写
int w = weights[i] - out * weights[i];
要使用std::stoi()
和std::to_string()
您需要有一个适当的
#include <string>
语句和 C++11 语言选项集(请参阅指向上述文档参考的链接(。
相关文章:
- std::ofstream 作为类成员删除复制构造函数?
- 使用 std::index_sequence 初始化具有固定大小数组成员的 POD 结构容器
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- 使用 std::async 时死锁,将来作为成员
- 可变参数模板参数扩展 类型为 std::function 的类成员
- FreeFileSync C++错误:'byte'不是 'std' 的成员
- 为什么 std::sort 找不到合适的(静态成员)函数重载?
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- 在模板化成员函数的返回类型中使用 std::enable_if 时的编译器差异
- 有没有办法避免为 std::variant 类成员中的所有类型编写构造函数?
- 是否允许类类型的 std::function 成员变量(不完整类型)?
- 访问 std:vector 的类成员 std:vector 在一个类中与另一个 std:vector
- std::异步与非静态成员函数
- 如何在 c++11 中静态断言 std::array 类成员进行排序?
- 将初始化器列表/聚合初始化转发到 std::array 成员
- C++ IDE 不会推断/自动完成对模板类中的 std::array 下标表达式的成员访问
- 在哪里可以找到 std::bitset 的数据成员?
- 没有'str'成员在 GCC 和 Clang 'std::basic_ostream<char>',但 MSVC 没有问题
- unique_ptr问题:不是'std'成员
- std::成员函数的异步调用