#include <cstdlib> #include <iostream> #include <vector> #include <string> #include <iterator> #include <fstream> using namespace std; typedef struct _NODE { string str; int id; _NODE(string str, int id) : str(str), id(id){}; friend ostream& operator<<(ostream &os, const _NODE &node) { return os << "(" << node.id << ", " << node.str << ")" << endl; } }NODE; class checkLen { public: checkLen(int min, int max) : m_min(min), m_max(max){}; bool operator()(const NODE &node) { return node.str.size() >= m_min && node.str.size() <= m_max; } private: int m_min; int m_max; }; int main(int argc, char *argv[]) { ifstream input("input.txt"); vector<NODE> node; string eachWord; cout << "words in file is: " << endl; while(input >> eachWord) { NODE temp(eachWord, rand() % 100); node.push_back(temp); cout << temp; } int min = 5, max = 8; vector<NODE>::size_type count = count_if(node.begin(), node.end(), checkLen(min, max)); cout << "words len in(5, 8)'s count is: " << count << endl; system("PAUSE"); return EXIT_SUCCESS; }