forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex19_18.cpp
More file actions
23 lines (22 loc) · 743 Bytes
/
Copy pathex19_18.cpp
File metadata and controls
23 lines (22 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
int main(int argc, char *argv[])
{
std::vector< std::string > v;
std::string a;
while (std::getline(std::cin,a)) {
v.push_back(a);
}
auto m = std::count_if(v.begin(),v.end(),std::mem_fn(&std::string::empty));
std::cout << "Using mem_fn,the number of empty lines:" << m << std::endl;
auto n = std::count_if(v.begin(),v.end(),std::bind(&std::string::empty,std::placeholders::_1));
std::cout << "Using bind,the number of empty lines:" << n << std::endl;
auto q = std::count_if(v.begin(),v.end(),[](std::string &tem){
return tem.empty();
});
std::cout << "Using lamba,the number of empty lines:" << q << std::endl;
return 0;
}