反转字符串比如hello world转为dlrow olleh,但我写的代码没办法保留空格,请问原因,以及怎么改。万分感谢。代码:
#include
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
string s;
int len;
int tem[1];
cout<<"Please enter a string:"<<endl;
cin>>s;
len=s.length();
for(int i=0;i<=(len/2);i++){
tem[0]=s[i];
s[i]=s[len-1-i];
s[len-1-i]=tem[0];
}
cout<<s<<endl;
return 0;
}