Logo

Programming-Idioms

History of Idiom 41 > diff from v47 to v48

Edit summary for version 48 by alok99:
New Cpp implementation by user [alok99]

Version 47

2019-09-26, 15:20:48

Version 48

2019-09-26, 15:47:14

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration
Code
std::string string_s("Example");
std::string string_t;
std::copy(string_s.crbegin(), string_s.crend(), std::back_inserter(string_t));
Doc URL
https://en.cppreference.com/w/cpp/string/basic_string/rbegin
Origin
https://en.cppreference.com/w/cpp/string/basic_string/rbegin