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

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2011年11月10日

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

  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 }


相关文章