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;
}




![[笔试强训day09]](https://img-blog.csdnimg.cn/direct/0efe72fbad0b476f8474d15793cb0ca7.png)














