【王道训练营 C/C++方向基础 60 题(31 您所在的位置:网站首页 王道程序员训练营多少钱一个月 【王道训练营 C/C++方向基础 60 题(31

【王道训练营 C/C++方向基础 60 题(31

2024-07-01 03:05| 来源: 网络整理| 查看: 265

31. 声明一个类 String,其数据成员为 char head[100],构造函数 String(char *Head)实现 head 的初始化,成员函数 void reverse()实现 head 内字符串的 逆序存放,成员函数 void print()实现 head 内字符串的输出。

#include #include using namespace std; class String; class String { public: String(char* Head) { strcpy(head,Head); } void reverse() { int len = strlen(head); for (int i = 0; i < len / 2; i++) { swap(head[i], head[len - 1 - i]); } } void print() { int len = strlen(head); for (int i = 0; i < len ; i++) { cout


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有