大致思路: 倒序遍历string,将每个字符装入vector< char >
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
vector<char> inversion(string str){
vector <char> str2;
int len=str.length();
for(int i=len-1;i>=0;i--){
str2.push_back(str[i]);
}
for(vector<char>::iterator it=str2.begin();it!=str2.end();it++)
{
cout<<*it;
}
return str2;
}
int main(int argc, char** argv) {
string str;
cin>>str;
inversion(str);
return 0;
}