字符串倒序
#include <iostream> #include <string> using namespace std; int main() { char str[1024]; cin>>str; int i = 0; while(str[i]!='\0') { i++; } int j= 0; int n=i; char str2[1024]; for(j=0; j<n; j++) { str2[j]=str[i-1]; i--; } str2[j] = '\0'; n=j; for(i=0,j=0; i<n;i++,j++) { str[i] = str2[j]; } cout<<str<<endl; cout<<str2<<endl; }