Reverse a string in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Reverse a string in c++

I saw in a video how to reverse a string using strrev(). searching in the internet I have found that strrev() is not a c or c++ function, actually in cplusplus webpage strrev() is not there, but, why this function works in c++? I have found that there is another way to reverse the string, using the function reverse(), both functions works, so... which one do I need to use in c++?

29th Jul 2018, 5:47 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
1 Answer
+ 9
strrev() does not appear to be standard. While it may be supported by some compilers, don't use it. In fact, there does not seem to be a standard predefined function in C which reverses a string. In C++, you can definitely count on std::reverse. https://code.sololearn.com/cJWnja94xBIA/?ref=app
29th Jul 2018, 6:16 AM
Hatsy Rei
Hatsy Rei - avatar