当前位置: 首页 > news >正文

C++ //练习 19.18 编写一个函数,使用count_if统计在给定的vector中有多少个空string。

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

练习 19.18 编写一个函数,使用count_if统计在给定的vector中有多少个空string。

环境:Linux Ubuntu(云服务器)
工具:vim

 

代码块
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;int countEmptyStrings(const vector<string> &vec){return count_if(vec.begin(), vec.end(), [](const string &str){return str.empty();});
}int main(){vector<string> strings = {"hello", "", "world", "", "!", ""};int emptyCount = countEmptyStrings(strings);cout<<"Number of empty strings: "<<emptyCount<<endl;return 0;
}

http://www.mrgr.cn/news/8984.html

相关文章:

  • eureka原理实践
  • 鸿蒙卡片传值app到卡片
  • 具有手势识别的动捕设备——mHand Pro VR数据手套
  • RISC-V vector(1) --- vector的引入与register说明
  • 2024中国AI Agent行业研究报告(PPT 可编辑)+2024中国AI Agent市场研究报告
  • FreeRTOS 快速入门(八)之任务通知
  • easypoi模板导出word并且合并行
  • 数据结构与算法的实现与优化
  • linux df -h时没有查到root盘,root文件夹带着锁或者叉号的解决办法
  • 进阶-7.管理工具
  • QChart绘制折线图
  • 【C++】函数模板特化:深度解析与应用场景
  • 【设计模式】模块模式和桥接模式
  • Android笔试面试题AI答之Kotlin(18)
  • postgresql 使用explain 进行SQL分析
  • ios白苹果修复办法有哪些?
  • 【微服务】springboot整合对象映射工具MapStruct使用详解
  • nginx做代理 转发前端请求到后端
  • 698. 划分为k个相等的子集
  • java日常管理