⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex1604.cpp

📁 teach yourself C++ in 21 days 第五版
💻 CPP
字号:
#include <iostream.h>
#include <string.h>

class String
{
   public:
      // constructors
      String();
      String(const char *const);
      String(const String &);
      ~String();

      // overloaded operators
      char & operator[](int offset);
      char operator[](int offset) const;
      String operator+(const String&);
      void operator+=(const String&);
      String & operator= (const String &);
      friend ostream& operator<<( ostream& theStream,String& theString);
      friend istream& operator>>( istream& theStream,String& theString);
      // General accessors
      int GetLen()const { return itsLen; }
      const char * GetString() const { return itsString; }
      // static int ConstructorCount;

    private:
      String (int);         // private constructor
      char * itsString;
      unsigned short itsLen;
};

ostream& operator<<( ostream& theStream,String& theString)
{
    theStream << theString.GetString();
    return theStream;
}

istream& operator>>( istream& theStream,String& theString)
{
    theStream >> theString.itsString;
    return theStream;
}

int main()
{
   String theString("Hello world.");
   cout << theString;
   cin >> theString;
   cout << theString;
   return 0;
}

⌨️ 快捷键说明

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