// @topic S-0314-09-02-10 C++ template class demo I // @brief Program demonstarting C++ templates #include <iostream> #include <string> #include <algorithm> template < char SpaceChar = ' ' > class SpacePolicy { public: static char get_space() { return SpaceChar; } }; template < typename SpacePolicyT = SpacePolicy<> > class Parser { std::string m_text; public: Parser( std::string text ) { m_text = text; } int parse() { int count = std::count( m_text.begin(), m_text.end(), SpacePolicyT::get_space() ); return count; } };//class Parser int main() { for (;;) { std::cout << "Enter text to count spaces or x to exit: "; std::string user_input; std::getline( std::cin, user_input ); // read line of text if ( user_input == "x" ) { break; } //Parser< SpacePolicy< '_' > > parser( user_input ); Parser<> parser( user_input ); std::cout << parser.parse() << " spaces found." << '\n'; } //std::cout << "Enter x to exit: "; //char pause; //std::cin >> pause; return 0; }