# C++ algorithm partition

#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <iostream>

// g++ 4.9.2 -std=c++11
// function that take a string and return true
// indicating the string has five characters
// or more
bool pred(const std::string &s)
{
return !(s.size() < 5);
}

int main()
{
std::vector<std::string> words;
std::string str;
while (std::cin >> str) {
words.push_back(str);
}
std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, " "));
std::cout << "\n";

auto it = std::partition(words.begin(), words.end(), pred);
std::copy(words.begin(), it, std::ostream_iterator<std::string>(std::cout, " "));
std::cout << "\n";

return 0;
}

from C++ primer 5th Exercise 10.13(P.387)

#### C++ 头文件algorithm 1——partition

2017-10-08 10:51:52

#### algorithm库函数——sort()和partition()

2016-12-26 09:43:11

#### STL algorithm算法partition, partition_copy(43)

2014-09-22 14:58:56

#### C++STL库之algorithm库

2016-03-31 15:51:15

#### algorithm库介绍之---- partition()方法和 stable_partition()方法

2012-09-15 15:37:32

#### k-medoids 算法思想

2013-03-19 10:56:57

#### 使用algorithm中的sort进行vector的自定义排序

2017-04-07 21:04:12

#### Intel Flash的驱动实现及提供给文件系统Flash File System的一些接口

2006-02-24 19:10:00

#### C++序列操作之std::partition

2015-08-14 10:34:28

#### C++/C++11中<algorithm>的使用

2017-09-19 21:44:34