#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void resort(char s[]) //或者是resort(char *s)
{
char temp;
for (int i=0,j=strlen(s)-1;i<j;i++,j--) //对j的初始化是关键
{
temp=s[i];s[i]=s[j];s[j]=temp;
}
}
int main()
{
char s1[]="this is a dog";
cout<<strlen(s1)<<endl; //求string中元素个数
cout<<s1<<endl; //之前的的字符串
resort(s1);
cout<<s1<<endl; //颠倒后的字符串
return 0;
}
PS:注意区分sizeof,strlen()和.size()的区别。