Using string function.

How do i reverse an inputted string but the last character of the string stays the same, say, inputted : "Hello12345" will return : "4321olleH5". Using cpp code.
Last edited on
A reverse loop using string size.

http://www.cplusplus.com/reference/string/string/size/

for (int i = str.size(); i > 0; i --)
{cout << str[i];}
Last edited on
How do i do it? I'm a beginner so i don't really understand the whole string function, char* and etc.
You have advanced from C to C++? Previous thread on reversal: http://www.cplusplus.com/forum/general/232994/

The "string" has documentation: http://www.cplusplus.com/reference/string/string/
There is also a generic "reverse": http://www.cplusplus.com/reference/algorithm/reverse/
string is a type. it wraps the old char array / char * in a class and modernizes all the hands-on stuff into a safer, more OOP approach with handy stuff like assignment operators that were lacking before.

focus on learning this and ignore char* style strings. If you need to deal with legacy code that uses char*, you can study it later once you have a better understanding of everything else.

Topic archived. No new replies allowed.