请各位大侠过来帮忙看一看这个代码有什么问题?我写的代码是:#include<iostream>//#include<sstream>//#include<numeric>#include<vector>#include<algorithm>#include <functional> using namespace std;vector<string> a = { "ssd", "bbblll", "ss", "wre", "sad", "adff", "asfdsgsdg", "wetrwetgsd" };bool check_size(const string &b, string::size_type sz){return b.size() >= sz;}void main(){auto wc = std::find_if(a.begin(), a.end(), std::bind(check_size, _1, 6));}编译环境:visual studio 2013报错:_1是未声明的标识符对比MSDN中对bind函数的使用,我也并没有语法错误呀?是什么问题呢#include <functional> #include <algorithm> #include <iostream> using namespace std::placeholders; void square(double x) { std::cout << x << "^2 == " << x * x << std::endl; } void product(double x, double y) { std::cout << x << "*" << y << " == " << x * y << std::endl; } int main() { double arg[] = {1, 2, 3}; std::for_each(&arg[0], arg + 3, square); std::cout << std::endl; std::for_each(&arg[0], arg + 3, std::bind(product, _1, 2)); std::cout << std::endl; std::for_each(&arg[0], arg + 3, std::bind(square, _1)); return (0); } MSDN实例代码运行正确
2 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
_1 _2 ...定义在placeholders这个namespace,所以要用 using namespace std::placeholders;
- 2 回答
- 0 关注
- 576 浏览
添加回答
举报
0/150
提交
取消