2017年計(jì)算機(jī)二級C++輔導(dǎo)實(shí)例編程(7)

字號:


    輸入一個字符串,將其逆序后輸出
    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 {//把字符串的兩邊一一調(diào)換
    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 }