Logo

Programming-Idioms

History of Idiom 41 > diff from v32 to v33

Edit summary for version 33 by programming-idioms.org:
Admin deletes impl 471

Version 32

2017-11-19, 03:06:05

Version 33

2017-11-19, 03:53:27

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
Imports
#include <stdlib.h>
#include <string.h>
Code
std::string t = s
std::reverse(std::begin(t),std::end(t));
Comments bubble
std::reverse is the built in way of reversing any array form of data. Can be assumed to be the fastest general implementation.