C++ //练习 10.24 给定一个string,使用bind和check_size在一个int的vector中查找第一个大于string长度的值。

C++ Primer(第5版) 练习 10.24

练习 10.24 给定一个string,使用bind和check_size在一个int的vector中查找第一个大于string长度的值。。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
/*************************************************************************
	> 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;
}
运行结果显示如下
相关推荐
行稳方能走远9 小时前
Android C++ 学习笔记3
android·c++
练习时长一年9 小时前
Leetcode热题100(跳跃游戏 II)
算法·leetcode·游戏
FL162386312912 小时前
[C#][winform]基于yolov8的水表读数检测与识别系统C#源码+onnx模型+评估指标曲线+精美GUI界面
开发语言·yolo·c#
小白菜又菜14 小时前
Leetcode 3432. Count Partitions with Even Sum Difference
算法·leetcode
cnxy18815 小时前
围棋对弈Python程序开发完整指南:步骤1 - 棋盘基础框架搭建
开发语言·python
wuhen_n15 小时前
LeetCode -- 15. 三数之和(中等)
前端·javascript·算法·leetcode
sin_hielo16 小时前
leetcode 2483
数据结构·算法·leetcode
程序员-周李斌16 小时前
Java 死锁
java·开发语言·后端
Xの哲學16 小时前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
大头流矢16 小时前
归并排序与计数排序详解
数据结构·算法·排序算法