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;
}
运行结果显示如下
相关推荐
whxnchy15 小时前
UDP多端口负载均衡实战
c++
上海合宙LuatOS15 小时前
Air780EPM通过MQTT上传温湿度数据
开发语言·人工智能·物联网·junit·luatos
sheeta199816 小时前
LeetCode 每日一题笔记 日期:2026.05.08 题目:3629. 素数跳跃最小次数
笔记·算法·leetcode
叼烟扛炮16 小时前
C++ 知识点08 类与对象
开发语言·c++·算法·类和对象
米粒116 小时前
力扣算法刷题 Day 63 Bellman_ford 算法
数据库·算法·leetcode
楼田莉子16 小时前
仿Muduo的高并发服务器:Http协议模块
linux·服务器·c++·后端·学习
你不是我我1 天前
【Java 开发日记】HTTP3 性能更好,为什么内网微服务依然多用 HTTP2?HTTP2 内网优势是什么?
java·开发语言·微服务
IT大白鼠1 天前
AIGC性能的关键瓶颈:算力、数据、算法三者如何互相制约?
算法·aigc
tjl521314_211 天前
04C++ 名称空间(Namespace)
开发语言·c++
ximu_polaris1 天前
设计模式(C++)-行为型模式-备忘录模式
c++·设计模式·备忘录模式