//关注备注部分知识点。
#include
#include
//1---需要了解cstring和string之间的区别 int main() { using namespace std; cout<<"Please Enter a string:\n"; string word; cin>>word;// // char temp;
//3--- int i,j; //
for(i=0,j=word.size()-1;i<=j;++i,--j)
for(i=0,j=word.length()-1;i<=j;++i,--j)
//2---word.size() word应该是个数组. word.length()和 word.size() 则表示数组的长度. 因为数组下标是从0开始的.所以 要-1 防止下标越界 { char temp;//内部声明temp在每次循环存在被分配和释放,相对for循环体前声明运行慢,循环结束即会释放 // char temp=word[i];
//3--- // char temp=word[i];
//3--- temp=word[i]; word[i]=word[j]; word[j]=temp; } cout<