14.38 write a class to check whether the length of a given String object is equal to a threshold value. Write a program using this object, count and report the number of words with a length of 1 in the input file, the number of words with a length of 2 ,..... the number of words with a length of 10.
# Include <iostream> # include <vector> # include <string> # include <algorithm> # include <fstream> using namespace STD; Class length {public: length (size_t N ): SZ (n) {} bool operator () (string & S) {return S. size () = SZ;} PRIVATE: size_t SZ;}; int main () {ifstream in ("4.txt"); string STR; vector <string> VEC; int arr [10]; while (in> Str) Vec. push_back (STR); For (size_t I = 0; I <10; ++ I) Arr [I] = count_if (VEC. begin (), VEC. end (), length (I + 1); For (size_t I = 0; I <10; ++ I) cout <arr [I] <""; cout <Endl; return 0 ;}
Lambda and function call Conversion