請各位大俠過來幫忙看一看這個代碼有什么問題?我寫的代碼是:#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 關注
- 684 瀏覽
添加回答
舉報
0/150
提交
取消