C++字符串运算程序
来源:互联网 发布:java三大框架视频教程 编辑:程序博客网 时间:2024/06/07 10:34
#include <cstdlib>
#include <iostream>
//#include<iomainip>
#include<string>
using namespace std;
class Mystring{
private:
char p[30];
int num;
public:
Mystring operator+(Mystring str1){
Mystring temp;
strcpy(temp.p,p);
strcat(temp.p,str1.p);
return temp;
}
Mystring operator-(Mystring str1)
{
Mystring temp;
strcpy(temp.p,p);
int i=0;
while(temp.p[i]!='/0')
{
if(temp.p[i]==str1.p[0])
{
for(int k=i;temp.p[k]!='/0';k++)
{
temp.p[k]=temp.p[k+1];
}
num++;
i--;
}
i++;
}
temp.num=num;
return temp;
}
void show()
{
cout<<p<<endl;
}
void show_num()
{
cout<<"共删除字符数:"<<num<<endl;
}
Mystring(char s1[])
{
num=0;
strcpy(p,s1);
}
Mystring()
{
num=0;
}
};
int main(int argc, char *argv[])
{
Mystring a("abcdef"),b("def");
Mystring c;
cout<<"字符串a=";
a.show();
cout<<"字符串b=:";
b.show();
c=a+b;
c.show();
c=c-"d";
cout<<"字符串c-/"d/"=";
c.show();
c.show_num();
system("PAUSE");
return EXIT_SUCCESS;
}
- C++字符串运算程序
- 高精度运算(c程序)
- 高精度运算(c程序)
- 高精度运算(c程序)
- C语言程序 运算符
- C语言 程序 位运算
- c程序字符串排序
- C程序的格式字符串
- C语言字符串解析程序
- 计算机百万亿次运算C程序
- 字符串运算
- 字符串运算
- # 的用法(c语言中) 字符串创建运算符
- C数据类型,变量,运算符,数组与字符串
- [c++]String字符串类的运算符重载
- C语言通过位运算筛选出字符串中的中文
- C/C++运算符重载实现字符串相加
- 大数的运算实现(C++、字符串)、Git使用示例
- 我关注的Blog
- WINpcap设置
- Linux启动过程综述(学习)
- IEGroup 的一些想法
- DG Broker 配置官网址
- C++字符串运算程序
- PKU 1611 并查集
- ubuntu 开机自动开启数字小键盘
- nand flash 原理(2)含实例
- 12092009小记
- C#制作Arcgis Engine鹰眼全过程(引自ESRI中国社区)
- 遗憾也美丽
- 幸福的生活
- 开发人员一定要加入收藏夹的网站