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
本文纯为本人记录,有网上诸多参考,请勿转发! 记录可能可能有点啰嗦,自己划重点吧!! (无论是生活还是工作,如果很困惑,千万不要消极一定要勇敢积极的面对它,不用说太多懂得人自然懂,一定要解决这个疑惑就 ...
随机推荐
- iOS - OC SQLite 数据库存储
前言 采用 SQLite 数据库来存储数据.SQLite 作为一中小型数据库,应用 iOS 中,跟前三种保存方式相比,相对比较复杂一些. 注意:写入数据库,字符串可以采用 char 方式,而从数据库中 ...
- iOS - OC NSNull 空值
前言 @interface NSNull : NSObject <NSCopying, NSSecureCoding> 作为占据空间的一个空值,如用在数组或字典中占据一个没有任何值的空间. ...
- mysql 中文字段排序( 按拼音首字母排序) 的查询语句
在处理使用Mysql时,数据表采用utf8字符集,使用中发现中文不能直接按照拼音排序 如果数据表tbl的某字段name的字符编码是latin1_swedish_ci select * from `tb ...
- zabbix监控系统客户端安装
原文:http://blog.chinaunix.net/uid-25266990-id-3387002.html 测试使用agentd监听获取数据. 服务端的安装可以查看http://blog.ch ...
- SSM框架——以注解形式实现事务管理
上一篇博文<SSM三大框架整合详细教程>详细说了如何整合Spring.SpringMVC和MyBatis这三大框架.但是没有说到如何配置mybatis的事务管理,在编写业务的过程中,会需要 ...
- Linux runlevel 运行级别
runlevel可以认为是系统状态,形象一点,您可以认为runlevel有点象微软的windows操作系统中的Normal,safemode,和Command prompt only. Linux系统 ...
- activiti jbpm相关资源
Activiti 5.16 用户手册 http://www.mossle.com/docs/activiti/index.html jBPM 4.4开发指南 http://www.mossle.com ...
- smarty 学习记录
smarty模版是比较大众化的一个模版,在php开发过程当中被很多开发者视为最友好的模版之一,学习smarty课程对于很多培训机构来说也是列入了培训课程之一,那么很多方面就需要我们学习了一. 安装首先 ...
- servlet 文件上传简易版
package cn.itcast.servlet; import java.io.File;import java.io.IOException;import java.util.List; imp ...
- aspcms标签使用经验
1.调用导航栏标签写法,sort是网站后台栏目管理的编号{aspcms:type sort=19} <a href="[type:link]" title="[ty ...