2011年计算机二级C++辅导实例编程(7)

2014-10-21 10:30:04 · 作者: · 浏览: 61

  输入一个字符串,将其逆序后输出


  01 #include


  02 #include


  03 using namespace std;


  04


  05 void SetStr(string &str)


  06 {


  07 int len=str.length();


  08 char temp;


  09 for (int i=0;i


  10 {//把字符串的两边一一调换


  11 temp=str[i];


  12 str[i]=str[len-1-i];


  13 str[len-1-i]=temp;


  14 }


  15 }


  16


  17 int main()


  18 {


  19 string a;


  20 cout<<"input"<


  21 cin>>a;


  22 SetStr(a);


  23 cout<


  24 return 0;


  25 }


  编辑推荐: