练习 10.24:给定一个 string,使用 bind 和 check_size 在一个 int 的 vector 中查找第一个大于 string 长度的值。
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
using namespace std::placeholders;
bool check_size(int length, string s)
{
return length > s.size();
}
int main()
{
string s;
cout << "请输入一个string:";
cin >> s;
vector<int> vint{0, 2, 4, 6, 8, 10, 12, 14, 16, 18};
auto firstBiggerValue = find_if(vint.begin(), vint.end(), bind(check_size, _1, s));
cout << "vector<int>中第一个大于string长度的值为:" << *firstBiggerValue << endl;
return 0;
}