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

📄 mystring.h

📁 一本语言类编程书籍
💻 H
字号:
// Exercise 14.1 MyString.h
// Definition of the MyString class representing strings

#ifndef MYSTRING_H
#define MYSTRING_H
namespace mySpace {

class MyString {
  public:
    MyString();                                // Default constructor
    MyString(const char* pString);             // Construct from a C-style string
    MyString(char ch, int n);                  // Construct from repeated character
    MyString(int number);                      // Construct string representation of integer
    MyString(const MyString& rString);         // Copy constructor
    ~MyString();                               // Destructor

    int length() const{ return strLength; }    // Return length excluding terminating null
    int find(char ch) const;                   // Find the occurrence of a character
    int find(const char* pString) const;       // Find the occurrence of a C-style string 
    int find(const MyString& rString) const;   // Find the occurrence of a MyString  as a sub-string
    void show() const;                         // Output the string
    MyString& operator=(const MyString& rhs);  // Assignment operator
  private:
    char* pStr;                                // Pointer to the string
    size_t strLength;                          // number of characters excluding terminating null
};

}  // End of namespace mySpace
#endif

⌨️ 快捷键说明

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