- /* Create a function that takes a string as its argument
- ~ and returns the string in reversed order.
- */
- std::string reverse(std::string str) {
- std::string s = "";
- // get length of "str"
- int len = str.size();
- // loop over "str" to reverse it
- for (int i=0; i < len; i++) {
- s += str.back();
- // str = last + str;
- str.pop_back();
- }
- return s;
- }
|