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
本文纯为本人记录,有网上诸多参考,请勿转发! 记录可能可能有点啰嗦,自己划重点吧!! (无论是生活还是工作,如果很困惑,千万不要消极一定要勇敢积极的面对它,不用说太多懂得人自然懂,一定要解决这个疑惑就 ...
随机推荐
- Windows Live Writer编写Octopress
Windows live Writer是一个可以用来离线编写,并发布博客的工具. Octopress是一个静态博客生成系统.使用群体多是geek,主要有显示代码清晰,git同步,并且不用购买空间的特点 ...
- iOS - OC Copy 拷贝
前言 copy:需要先实现 NSCopying 协议,创建的是不可变副本. mutableCopy:需要实现 NSMutableCopying 协议,创建的是可变副本. 浅拷贝:指针拷贝,源对象和副本 ...
- c++ string的实现。
第三次做了.只是做个复习.偶然发现之前的版本有内存泄露.基本功还是不过关.这次应该没有内存泄漏了.虽然是个简单版本. 1)了解堆,栈,值copy. 2)几个常用的c的字符函数和c中的char 如何表示 ...
- 【转】《深入理解计算机系统》C程序中常见的内存操作有关的典型编程错误
原文地址:http://blog.csdn.net/slvher/article/details/9150597 对C/C++程序员来说,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构 ...
- Python中的join()函数split()函数
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的 ...
- Delphi 使用之函数
函数由一句或多句代码组成,可以实现某个特定的功能.使用函数可以使代码更加易读.易懂,加快编程速度及减少重复代码.过程与函数类似,过程与函数最重要的区别在于,过程没有返回值,而函数能有返回值. ...
- 【Oracle 数据迁移】环境oracle 11gR2,exp无法导出空表的表结构【转载】
今天做数据迁移,但是发现有些空表无法exp,后来找到问题所在. [原文]:http://www.cnblogs.com/wenlong/p/3684230.html 11GR2中有个新特性,当表无数据 ...
- hiho1093_spfa
题目 SPFA模板题,题目中数据可能有两个点之间有多条边直接相连,使用 unordered_map< int, unordered_map< int, int>>, 来存储图的 ...
- C++ Primer 笔记(1)基础中的战斗机 输入输出 对输入不定数据处理
今天打算再重新好好的看一遍C++ Primer这本很经典的书籍,笔记开始: 1.每个C++程序都包含一个或者多个函数,其中必须有一个main,操作系统通过调用main入手运行程序: 2.函数包括:返回 ...
- 【bzoj1053】反素数
[bzoj1053]反素数 题意 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例 ...