cstring.h

来自「是一个用C++编写的图形编辑器!」· C头文件 代码 · 共 78 行

H
78
字号
// cstring.h: interface for the cstring class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CSTRING_H__5078DAFE_99BA_423C_80A0_C13C219A2708__INCLUDED_)
#define AFX_CSTRING_H__5078DAFE_99BA_423C_80A0_C13C219A2708__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <iostream.h>
#include <string.h>


class cstring  
{
private:
	char * _contents;//字符串内容
	unsigned _length;//字符串长度

public:
	static unsigned _pagesize;//一页长度
	cstring();
	cstring(unsigned len);
	cstring(const cstring& s);	  //copy-constructor
	cstring(const char* str);  
	cstring(const char c);
	cstring(const char* str,unsigned len);
	int Length()
	{
		return _length;
	}
	char* contents()
	{
		return _contents;
	}
	virtual ~cstring()
	{
		delete _contents;
	}
	operator char*() const	 //the automatic type conversion is extremely helpful
	{
		return _contents;
	}
	operator int() const
	{
		return _length;
	}
	char& operator[](unsigned index); //得到指定的空间, is a L-value
	const char& operator[](unsigned index) const;  //取得相应空间的值, is R-value
	cstring& operator=(const cstring& s);
	bool operator==(const cstring& s);
	void Empty();
	void SetAt( unsigned nIndex, char ch );
	cstring Left(int ncount) const;
	cstring Right( int nCount ) const;
	cstring& Insert(unsigned nIndex,const char& ch);
	cstring& Insert(unsigned nBegin,const cstring& str);
	cstring& Delete(unsigned nIndex);//删除第nIndex个字符
	cstring Delete(unsigned nBegin,unsigned nCount);//删除从nBegin开始的nCount个字符串
	int Find(const char& ch);
	int Find(unsigned nNumber,char ch);//第nNumber行字符ch所处的偏移(相对于行首)
	cstring SubString(unsigned nBegin,unsigned nCount);
	cstring& Replace(unsigned pos,unsigned len,const char* s);
	friend cstring operator+(const cstring& s1,const char& ch);
	friend cstring operator+(const char& ch,const cstring& s2);
	friend cstring operator+(const cstring& s1,const cstring& s2);
	cstring& operator+=(const char& ch);
	cstring& operator+=(const cstring& s2);
	friend ostream& operator<<(ostream& output,cstring& s);
	friend istream& operator>>(istream& input,cstring& s);
	class Error{ };
};


#endif // !defined(AFX_CSTRING_H__5078DAFE_99BA_423C_80A0_C13C219A2708__INCLUDED_)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?