Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ reverse string function

Status
Not open for further replies.

nappaji

Programmer
Mar 21, 2001
76
0
0
US
I know how to reverse a string using C, but how do you write a function in C++ to reverse a string???

Thanks
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top