/////////////////////////////////////////////////////////////////// // caser.cpp - Solution of MT#3-Q8 // // // // This is a demo showing how to convert a string reference to // // upper case characters. // /////////////////////////////////////////////////////////////////// #include #include typedef std::string str; class caser { public: caser(str &change) : _cased(change) {} void up() { for(unsigned i=0; i<_cased.length(); ++i) _cased[i] = toupper(_cased[i]); } void down() { for(unsigned i=0; i<_cased.length(); ++i) _cased[i] = tolower(_cased[i]); } private: str& _cased; }; int main() { str change = "This Will Be Changed To All One Case"; std::cout << "\n " << change; std::cout << "\n " << (caser(change).up(), change); std::cout << "\n " << (caser(change).down(), change) << "\n\n"; }