C++ day1 作业练习

整理思维导图

定义自己的命名空间my_sapce,在my_sapce中定义string类型的变量s1,再定义一个函数完成对字符串的逆置。

复制代码
#include <iostream>
#include <cstring>

using namespace std;
namespace my_space
{
    string s1;
}

void show()
{
    cout<<"hello"<<endl;
}
void re(char *p)
{
    if(NULL == p){
        return ;
    }
    //abcde
    char *head = p;
    char *tail = p+strlen(p)-1;
    char temp;

    while(head < tail){
        temp = *head;
        *head = *tail;
        *tail = temp;
        head++;
        tail--;
    }
}

int main()
{
    cout<< "请输入字符串:" <<endl;
    cin >> my_space::s1;
    char buf[100];
    strcpy(buf,my_space::s1.data());

    re(buf);
    cout<< buf<< endl;

    return 0;
}
相关推荐
感哥6 小时前
C++ 多态
c++
沐怡旸12 小时前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River41615 小时前
Javer 学 c++(十三):引用篇
c++·后端
感哥18 小时前
C++ std::set
c++
侃侃_天下19 小时前
最终的信号类
开发语言·c++·算法
博笙困了19 小时前
AcWing学习——差分
c++·算法
echoarts19 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix19 小时前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
青草地溪水旁19 小时前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(2)
c++·设计模式·抽象工厂模式
青草地溪水旁19 小时前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(1)
c++·设计模式·抽象工厂模式