1. 程式人生 > >學習筆記 c++ (倒敘輸出string,有空格輸入)

學習筆記 c++ (倒敘輸出string,有空格輸入)

#include<iostream> #include<string> #include<string.h>

using namespace std;

string change(string a, int n) {     int i=0;     int j=n-1;     char tmp;     for(i,j;i<n/2;i++,j--)     {         tmp = a[i];         a[i] = a[j];         a[j] = tmp;     }     cout<<a<<endl;     string b = a;     return b; }

int main(int argc, char** argv) {     string a,s;     int n;     cout<<"請輸入你的字串:";     getline(cin,a);     n = a.size();     cout<<"長度:"<<n<<endl;

    s = change(a,n);     cout<<s<<endl; }