C++ for迴圈一些獨特demo
阿新 • • 發佈:2018-12-09
string word = "stresseds";
//cin>>word;
char temp;
int i,j;
cout<<"word.size():"<<word.size()<<endl;
for (j=0,i=word.size() -1;j<i;i--,j++)
{
temp = word[i];
word[i] = word[j];
word[j] = temp;
cout<<"j:"<<j<<endl;
cout<<"i:"<<i<<endl;
}
cout<<word<<"\nDone\n"<<endl;
string word = "stresseds";
//cin>>word;
char temp;
int i,j;
cout<<"word.size():"<<word.size()<<endl;
for (j=0,i=word.size() -1;j<i;--i,++j)
{
temp = word[i];
word[i] = word[j];
word[j] = temp;
cout<<"j:"<<j<<endl;
cout<<"i:"<<i<<endl;
}
cout<<word<<"\nDone\n"<<endl;