#include <iostream>
#include <windows.h> using namespace std; const int Max = +;
class MyString
{
public: MyString()
{
this -> m_pchData = new char[Max];
this -> Length = ; }
void Init(char* a1) // 初识化
{
int l = strlen(a1);
this->Length = l;
memcpy(this->m_pchData,a1,l);
} int GetLength() const
{
return this->Length;
} bool IsEmpty()
{
if (this->Length==)
return true;
else return false;
} char GetAt(int nIndex) const
{
return this->m_pchData[nIndex-];
}
void Empty();
MyString(const MyString& a1);
char operator[](int nIndex) const;
void SetAt(int nIndex, char a1)
{
if (nIndex>=this->Length||nIndex<)
{
cout << "输入位置有误" << endl;
}
else
{
this->m_pchData[nIndex-] = a1;
} }
char* GetString ()
{
return this->m_pchData;
}
int GetLength()
{
return this->Length;
} const char* operator=(const char* stringSrc)
{
int l = strlen(stringSrc);
this->Length = l;
memset(this->m_pchData,,sizeof(this->m_pchData));
memcpy(this->m_pchData,stringSrc,l);
}
const char operator=(char a1)
{
this->Length = ;
memset(this->m_pchData,,sizeof(this->m_pchData));
this->m_pchData[] = a1; }
const char* operator+=(const char* string)
{
int l = strlen(string) ;
for (int i = ;i<l;i++)
{
this->m_pchData[this->Length+i] = string[i];
}
this->Length += l; }
const char* operator+=(char a1)
{ this->m_pchData[this->Length] = a1;
this->Length++;
}
int Replace(char lpszOld, char lpszNew)
{
for (int i = ;i<this->Length;i++)
{
if (this->m_pchData[i]==lpszOld)
{
this->m_pchData[i] = lpszNew;
}
}
}
int Remove(char chRemove);
int Insert(int nIndex, char ch);
char* GetBuffer(int Index)
{
if (Index >= this->Length||Index<)
{
cout << "输入有误" << endl;
}
else
{
int iNum = ;
int b = this->Length-Index+;
cout << b << endl;
char* a = new char[this->Length-Index+];
for (int i = Index-;i<this->Length;i++)
{
a[iNum++] = this->m_pchData[i];
} return a;
} }
private: char* m_pchData;
int Length; };
VOID operator<<(ostream& os,MyString& a1)
{
cout << a1.GetLength() << endl;
cout << a1.GetString() << endl;
} int main()
{
MyString mystring;
char a[] = "Hello Worldddddddddddddddddddd";
mystring.Init(a);
//cout << mystring.GetLength() << endl;
/* if (mystring.IsEmpty())
{
cout << "Empty" << endl;
}
else
{
cout << "Not Empty" << endl;
} cout << mystring.GetAt(3) << endl; mystring.SetAt(3,'a');
cout << mystring; char a1[20] = "gnajhg";
mystring += a1;
cout << mystring ;
*/ cout << mystring.GetBuffer() << endl;
cout << mystring ; return ;
}

cstring 的重载的更多相关文章

  1. 头文件 string.h cstring string 区别

    1.#include <cstring>   //不可以定义string s:可以用到strcpy等函数using   namespace   std; #include <stri ...

  2. CString用法总结

    概述:CString是MFC中提供的用于处理字符串的类,是一种很有用的数据类型. 它很大程度上简化了MFC中的许多操作,使得MFC在做字符串操作时方便了很多. 不管怎样,使用CString有很多的特殊 ...

  3. CString string char* char 之间的字符转换(多种方法)

    在写程序的时候,我们经常遇到各种各样的类型转换,比如 char* CString string 之间的互相转换.首先解释下三者的含义. CString 是一种很有用的数据类型.它们很大程度上简化了MF ...

  4. CString转换成int CString类相应函数

    CString 型转化成 int 型 把 CString 类型的数据转化成整数类型最简单的方法就是使用标准的字符串到整数转换例程. 虽然通常你怀疑使用_atoi()函数是一个好的选择,它也很少会是一个 ...

  5. C++赋值运算符、函数调用运算符、下标运算符(“=”、“()”、“[]”)重载

    #include <iostream>#include <assert.h>#include <string.h> using namespace std; cla ...

  6. C++———库函数cstring及string方法解读

    1.string与cstring区别 <string>是C++标准库头文件.包含了拟容器class std::string的声明(不过class string事实上只是basic_stri ...

  7. C++中cstring.h和string.h的区别

    转载:https://blog.csdn.net/qian_chun_qiang/article/details/80648691 1.string与cstring有什么区别 <string&g ...

  8. hash_map原理及C++实现

    一.数据结构:hash_map原理  hash_map基于hash table(哈希表).哈希表最大的长处,就是把数据的存储和查找消耗的时间大大减少,差点儿能够看成是常数时间:而代价不过消耗比較多的内 ...

  9. 独立看第一个C++程序到最终结果log----2019-04-15

    本文纯为本人记录,有网上诸多参考,请勿转发! 记录可能可能有点啰嗦,自己划重点吧!! (无论是生活还是工作,如果很困惑,千万不要消极一定要勇敢积极的面对它,不用说太多懂得人自然懂,一定要解决这个疑惑就 ...

随机推荐

  1. andriod之摄像头驱动流程

    camera成像原理: 景物通过镜头生产光学图像投射到sensor表面上,然后转为模拟电信号,经过数模变成数字图像信号,在经过DSP加工出来,然后在通过IO接口传输到CPU处理. 由于摄像头满足总线. ...

  2. poj1113Wall(凸包)

    链接 顺便整理出来一份自己看着比较顺眼的模板 #include <iostream> #include<cstdio> #include<cstring> #inc ...

  3. (四)C语言柔性数组、指针赋值

    一.柔性数组 今天看了公司的代码,发现一个很奇怪的问题,后来自己写了类似代码,我先把代码贴出来吧. #include<stdio.h> #include<string.h> # ...

  4. system v和posix的共享内存对比 & 共享内存位置

    参考 http://www.startos.com/linux/tips/2011012822078.html 1)Linux和所有的UNIX操作系统都允许通过共享内存在应用程序之间共享存储空间. 2 ...

  5. 基础2 JVM

    1. 内存模型以及分区,需要详细到每个区放什么. //运行时数据区域 方法区 Method Area 各个线程共享的内存区域 存储已被虚拟机加载的类信息 常量 静态变量 即时编译器编译后的代码 虚拟机 ...

  6. Eclipse用Tomcat插件部署Java Web项目

    Eclipse版本3.7.2,Tomcat插件是3.3 详细步骤如下: 1.下载tomcatPlugin插件 tomcatPlugin下载地址http://download.csdn.net/deta ...

  7. Redis常用的基本命令整理

    SET key value [EX seconds] [PX milliseconds] [NX|XX] 设置缓存 K-V,如果 key 已经存在,则重写 EX seconds -- 设置过期时间, ...

  8. pysam - 多种格式基因组数据(sam/bam/vcf/bcf/cram/…)读写与处理模块(python)

    在开发基因组相关流程或工具时,经常需要读取.处理和创建bam.vcf.bcf文件.目前已经有一些主流的处理此类格式文件的工具,如samtools.picard.vcftools.bcftools,但此 ...

  9. linux笔记:RPM软件包管理-yum在线管理

    ip地址配置: 用ifconfig命令只能配置ip和子网掩码,这样只能访问内网:如果需要访问公网则还必须要网关和DNS. 使用setup工具配置ip: 网络yum源配置: 常用yum命令:查询 常用y ...

  10. python 练习 28

    ython pass是空语句,是为了保持程序结构的完整性. pass 不做任何事情,一般用做占位语句. Python 语言 pass 语句语法格式如下: pass 实例: #!/usr/bin/pyt ...