/* Lecture code 8.2 * * ConvertToUpperCase and ConvertToLowerCase. Note the :: madness here * is for g++ / XCode but is not necessary in MSVC++. */ #include #include // for toupper, tolower #include #include // for transform using namespace std; string ConvertToUpperCase(string input) { /* Apply toupper to each element and store it back in itself. Note that the icky * :: is not needed in Visual Studio. */ transform(input.begin(), input.end(), input.begin(), ::toupper); return input; } string ConvertToLowerCase(string input) { /* Apply tolower to each element and store it back in itself. */ transform(input.begin(), input.end(), input.begin(), ::tolower); return input; } int main() { cout << ConvertToUpperCase("this is upper case!") << endl; cout << ConvertToLowerCase("THIS IS LOWER CASE!") << endl; return 0; }