C++ Primer(第5版) 練習 10.24
練習 10.24 給定一個string,使用bind和check_size在一個int的vector中查找第一個大于string長度的值。。
環境:Linux Ubuntu(云服務器)
工具:vim
?
代碼塊
/*************************************************************************> File Name: ex10.24.cpp> Author: > Mail: > Created Time: Sun 03 Mar 2024 08:43:07 PM CST************************************************************************/#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
using namespace placeholders;bool check_size(const int &n, string::size_type sz){return n > sz;
}int main(){string str;cout<<"Enter string: ";cin>>str;string::size_type sz = str.size();vector<int> number;int num;cout<<"Enter numbers: ";while(cin>>num){number.push_back(num);if(cin.get() == '\n'){break;}}auto wc = find_if(number.begin(), number.end(), bind(check_size, _1, sz));cout<<*wc<<endl;return 0;
}