Oct 27, 2002 #1 nappaji Programmer Mar 21, 2001 76 US I know how to reverse a string using C, but how do you write a function in C++ to reverse a string??? Thanks
I know how to reverse a string using C, but how do you write a function in C++ to reverse a string??? Thanks
Oct 27, 2002 #2 chipperMDW Programmer Mar 24, 2002 1,268 US Answer #1: Don't. They already wrote one. To reverse string str, just do: #include <algorithm> reverse( str.begin(), str.end() ); Answer #2: Pretty much the same way you'd do it in C. The string class supports operator[], so you can treat it just like a char* in that regard. Upvote 0 Downvote
Answer #1: Don't. They already wrote one. To reverse string str, just do: #include <algorithm> reverse( str.begin(), str.end() ); Answer #2: Pretty much the same way you'd do it in C. The string class supports operator[], so you can treat it just like a char* in that regard.