1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <algorithm> #include <functional> #include <iostream> #include <string> std::string &tolower (std::string &s) { std::transform(s.begin(), s.end(), s.begin(), std::ptr_fun<int, int>(std::tolower)); return s; } std::string &toupper (std::string &s) { std::transform(s.begin(), s.end(), s.begin(), std::ptr_fun<int, int>(std::toupper)); return s; } class lowerer { public: lowerer (std::string &s) : myString(s) { } friend std::istream &operator>> (std::istream &is, const lowerer &s) { return is >> s.myString; } ~lowerer () { tolower(myString); } private: std::string &myString; }; class upperer { public: upperer (std::string &s) : myString(s) { } friend std::istream &operator>> (std::istream &is, const upperer &s) { return is >> s.myString; } ~upperer () { toupper(myString); } private: std::string &myString; }; int main () { using namespace std; string s; cin >> lowerer(s); cout << s << endl; cin >> upperer(s); cout << s << endl; return 0; } |