C++ examples for STL:string
Printing a string Backward, convert case
#include <iostream> #include <string> int main(int argc, const char* argv[]) { std::cout << "Enter a string to have it reversed: "; std::string input;// w ww. j ava 2s . co m std::getline(std::cin, input); std::string::reverse_iterator it = input.rbegin(); while (it != input.rend()) { int ascii = *(it++); if ((ascii >= 97) && (ascii <= 122)) ascii = (ascii - 32); else if ((ascii >= 65) && (ascii <= 90)) ascii = (ascii + 32); char c = ascii; std::cout << c; } std::cout << std::endl; return 0; }