#include <string> #include <iostream> using namespace std; /* 循环实现 string Reverse(string str) { string S; int n=str.size(); while(n>0) { n--; S+=str[n]; } return S; }*/ string Reverse(string str) {//递归实现 static string S; static n=str.size(); if(n>0) { n--; S+=str[n]; Reverse( str); } return S; } void main() { string str="123456789"; string str2= Reverse(str); cout<<str2<<endl; }

评论