Skip to content

Latest commit

 

History

History
40 lines (37 loc) · 971 Bytes

File metadata and controls

40 lines (37 loc) · 971 Bytes
#include <iostream>
using std::cin; using std::cout; using std::endl; using std::cerr;
#include <fstream>
using std::ifstream;
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <algorithm>
using std::partition;

bool isMtf(const string &s){
    return s.size() > 5;
}

int main() {
    vector<string> vs;
    string pt("/home/raymain/CLionProjects/CPPLv1/test.txt");
    ifstream input(pt);
    if (input.is_open()){
        string tmp;
        while (input >> tmp)
            vs.push_back(tmp);
        cout << "Original: \n";
        for (const auto &a : vs)
            cout << a << " ";
        cout << endl;
        cout << "Partition by predicate: \n";
        auto vsPe = partition(vs.begin(), vs.end(), isMtf);
        for (auto it = vs.cbegin(); it != vsPe; ++it)
            cout << *it << endl;
        cout << endl;
    } else {
        cerr << "Failed to open file" << endl;
        return EXIT_FAILURE;
    }
}