13,824
社区成员
发帖
与我相关
我的任务
分享
#ifndef STRING_H
#define STRING_H
#include<iostream>
using namespace std;
class String
{
private:
char *str;
int len;
static int num_strings;
static const int CINLIM=80;
public:
String(const char *s);
String();
String(const String &);
~String();
int length()const{return len;}
//overloaded operator methods
String & operator=(const String &);
String & operator=(const char *);
char & operator[](int i);
const char & operator[](int i)const;
//overloaded operator friend
friend bool operator<(const String &st,const String &st2);
friend bool operator>(const String &st,const String &st2);
friend bool operator==(const String &st,const String &st2);
friend ostream & operator<<(ostream &os,const String &st);
friend istream & operator>>(istream &is,String & st);
//static function
static int HowMany();
};
#endif // STRING_H
istream & operator>>(istream & is,const String &st)
{
char temp[String::CINLIM];
is.get(temp,String::CINLIM);
if(is)
st=temp;
while(is&&is.get()!='\n')
continue;
return is;
}