| 9 | std::string reverse(std::string str); |
| 10 | |
| 11 | int main() |
| 12 | { |
| 13 | std::string sentence; |
| 14 | std::cout << "Enter a sequence of characters, then press 'Enter': " << std::endl; |
| 15 | getline(std::cin, sentence); |
| 16 | |
| 17 | std::cout << "\nYour sequence in reverse order is:\n"; |
| 18 | std::cout << reverse(sentence) << std::endl; |
| 19 | |
| 20 | std::cout << "\nHere is a demonstration of reverse() working with a C-style string:\n"; |
| 21 | |
| 22 | char stuff[] {"abcdefg"}; // C-style string |
| 23 | std::cout << "\nThe original string is: \"" << stuff << "\"" |
| 24 | << "\nReversed it becomes: \"" << reverse(stuff) << "\"" << std::endl; |
| 25 | } |
| 26 | |
| 27 | // Reverse a string in place |
| 28 | // The code here is working with a copy of the argument |