C++day1思維導圖
定義自己的命名空間my_sapce,在my_sapce中定義string類型的變量s1,再定義一個函數完成對字符串的逆置
#include <iostream>using namespace std;namespace my_space {string s1="abc123";string recover(string s){int i=0;int j=s.size()-1;while(i<j){char t=s.at(i);s.at(i)=s.at(j);s.at(j)=t;i++;j--;}return s;}
}using namespace my_space;
int main()
{string str=s1;cout << "str=" << str <<endl;string rstr=recover(str);cout << "rstr=" << rstr <<endl;return 0;
}