head.h

来自「一个关于标准string类的C++程序」· C头文件 代码 · 共 73 行

H
73
字号
#ifndef STRING1_H
#define STRING1_H


#include <iostream>

//using namespace std;
using std::ostream;
using std::istream;

class String {
	friend ostream &operator<<( ostream &, const String & );
	friend istream &operator>>( istream &, String & );

public:

	String(const char * = "" );
	String(const String & );
	~String();

	const String &operator=( const String & );
	const String &operator+=( const String & );

	bool operator!() const;
	bool operator==( const String & ) const;
	bool operator<(const String & ) const;

	//test s1 != s2
	bool operator!=( const String & right ) const
	{
		return !( *this == right );

	}

	//test s1>s2
	bool operator>( const String &right ) const
	{
		return right < *this;

	}

	//test s1<=s2
	bool operator<=(const String &right ) const
	{
		return !(right < *this );

	}

	//test s1>=s2
	bool operator>=( const String &right ) const
	{
		return !(*this < right );

	} 
	//end function operator

	
	char &operator[]( int );
	const char &operator[]( int ) const;

	String operator()( int, int );

	int getLenth() const;

private:
	int length;
	char *sPtr;

	void setString( const char * );

};

#endif

⌨️ 快捷键说明

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