cstring 的重载
#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 的重载的更多相关文章
- 头文件 string.h cstring string 区别
1.#include <cstring> //不可以定义string s:可以用到strcpy等函数using namespace std; #include <stri ...
- CString用法总结
概述:CString是MFC中提供的用于处理字符串的类,是一种很有用的数据类型. 它很大程度上简化了MFC中的许多操作,使得MFC在做字符串操作时方便了很多. 不管怎样,使用CString有很多的特殊 ...
- CString string char* char 之间的字符转换(多种方法)
在写程序的时候,我们经常遇到各种各样的类型转换,比如 char* CString string 之间的互相转换.首先解释下三者的含义. CString 是一种很有用的数据类型.它们很大程度上简化了MF ...
- CString转换成int CString类相应函数
CString 型转化成 int 型 把 CString 类型的数据转化成整数类型最简单的方法就是使用标准的字符串到整数转换例程. 虽然通常你怀疑使用_atoi()函数是一个好的选择,它也很少会是一个 ...
- C++赋值运算符、函数调用运算符、下标运算符(“=”、“()”、“[]”)重载
#include <iostream>#include <assert.h>#include <string.h> using namespace std; cla ...
- C++———库函数cstring及string方法解读
1.string与cstring区别 <string>是C++标准库头文件.包含了拟容器class std::string的声明(不过class string事实上只是basic_stri ...
- C++中cstring.h和string.h的区别
转载:https://blog.csdn.net/qian_chun_qiang/article/details/80648691 1.string与cstring有什么区别 <string&g ...
- hash_map原理及C++实现
一.数据结构:hash_map原理 hash_map基于hash table(哈希表).哈希表最大的长处,就是把数据的存储和查找消耗的时间大大减少,差点儿能够看成是常数时间:而代价不过消耗比較多的内 ...
- 独立看第一个C++程序到最终结果log----2019-04-15
本文纯为本人记录,有网上诸多参考,请勿转发! 记录可能可能有点啰嗦,自己划重点吧!! (无论是生活还是工作,如果很困惑,千万不要消极一定要勇敢积极的面对它,不用说太多懂得人自然懂,一定要解决这个疑惑就 ...
随机推荐
- spring的下载地址(转)
http://hi.baidu.com/jaimy_jie/item/d699cecdc5d3a354bdef6990 SPRING官方网站改版后,建议都是通过 Maven和Gradle下载,对不使用 ...
- iOS - OC NSSize 尺寸
前言 结构体,这个结构体用来表示事物的宽度和高度. typedef CGSize NSSize; struct CGSize { CGFloat width; CGFloat height; }; t ...
- iOS - OC NSPoint 位置
前言 结构体,这个结构体用来表示事物的一个坐标点. typedef CGPoint NSPoint; struct CGPoint { CGFloat x; CGFloat y; }; typedef ...
- Spring对Hibernate事务管理
谈Spring事务管理之前我们想一下在我们不用Spring的时候,在Hibernate中我们是怎么进行数据操作的.在Hibernate中 我们每次进行一个操作的的时候我们都是要先开启事务,然后进行数据 ...
- android设备休眠机制
如果一开始就对Android手机的硬件架构有一定的了解,设计出的应用程序通常不会成为待机电池杀手,而要设计出正确的通信机制与通信协议也并不困难.但如果不去了解而盲目设计,可就没准了. 首先Androi ...
- Android提高篇之自定义dialog实现processDialog“正在加载”效果、使用Animation实现图片旋转
知识点: 1.使用imageview.textview自定义dialog 2.使用Animation实现图片旋转动画效果 3.通过自定义theme去掉dialog的title 没有使用progres ...
- JavaScript设计模式与开发实践 - 策略模式
引言 本文摘自<JavaScript设计模式与开发实践> 在现实中,很多时候也有多种途径到达同一个目的地.比如我们要去某个地方旅游,可以根据具体的实际情况来选择出行的线路. 如果没有时间但 ...
- LinuxShell脚本攻略--第一章 小试牛刀
使用 shell 进行数学运算: #!/bin/bash no1=; no2=; let result=no1+no2 echo $result result=$[ $no1 + no2 ] resu ...
- 【转】 Android自定义捕获Application全局异常
大家都知道,现在安装Android系统的手机版本和设备千差万别,在模拟器上运行良好的程序安装到某款手机上说不定就出现崩溃的现象,开发者个人不可能购买所有设备逐个调试,所以在程序发布出去之后,如果出现了 ...
- 指针转换(C# 编程指南)
原文地址:https://msdn.microsoft.com/zh-cn/library/etb4xxec.aspx 下表显示了预定义的隐式指针转换.隐式转换可能在多种情形下发生,包括调用方法时和在 ...