亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mystring.cpp

?? 一本語言類編程書籍
?? CPP
字號:
// Exercise 14.5 MyString.cpp
// Definitions for member of the MyString class

#include "MyString.h"
#include <cstdlib>
#include <iostream>
using std::cout;
using std::endl;

namespace mySpace {

  // Default constructor
  MyString::MyString() {
    strLength = 0;               // Length excludes terminating null - this is empty string
    pStr = new char[1];          // Allocate space for string in the free store
    *pStr = '\0';                // Store terminating null
  }

  // Construct from a C-style string
  MyString::MyString(const char* pString) {
    strLength = strlen(pString);  // strlen() returns length excluding terinating null
    pStr = new char[strLength+1]; // Space must allow for null, hence strLength+1
    strcpy(pStr, pString);        // Copy argument string to data member
  }

  // Construct from repeated character
  MyString::MyString(char ch, int n) {
    strLength = n;
    pStr = new char[strLength+1];
    for(unsigned int i = 0 ; i<strLength ; *(pStr+i++) = ch) // 3rd expression stores ch then increments i
      ;                                             // No loop statement...
    *(pStr+strLength) = '\0';     // Store terminating null
  }

  // Construct string representation of integer
  MyString::MyString(int number) {
    char buffer[20];                    // Buffer to store string representation
    int temp = number;
    if(number<0)                        // If it is negative, 
      number = -number;                 // reverse the sign

    // Convert digits to characters in reverse order 
    int len = 0;
    do {
      buffer[len++] = static_cast<char>('0' + number%10);
      number /= 10;
    }while(number>0);
    if(temp<0)                          // If it was negative
      buffer[len++] = '-';              // Append a minus sign
    buffer[len] = '\0';                 // Apeend terminal \0

    strLength = len;                    // Store length of string

    pStr = new char[strLength+1];       // Allocate space
    std::strcpy(pStr, buffer);          // Copy string to data member
    // String is reversed so reverse it in place
    char ch = 0;
    for(int i = 0, j = len-1 ; i<j ; i++, j--) {
      ch = pStr[i];
      pStr[i] = pStr[j];
      pStr[j] = ch;
    }
  }

  // Copy constructor
  // Needs to allocate space for a copy of the string, then copy it
  MyString::MyString(const MyString& rString) {
    strLength = rString.strLength; // Store the length
    pStr = new char[strLength+1];  // Allocate the required space
    strcpy(pStr, rString.pStr);    // Copy the string
  }

  // Destructor
  // releases free store memory allocated to store string
  MyString::~MyString() {
    delete[] pStr;                 // Must use array form of delete here
  }

  // Find the position of a character
  // Compares succesive characters in the satring with the argument
  int MyString::find(char ch) const   {
    for(unsigned int i = 0 ; i<strLength ; i++)
      if(ch == *(pStr+i))           // If we find the character,
        return i;                   // return its position,
    return -1;                      // otherwise return -1
  }

  // Find the position of a string
  // Searches for the first character of the substring
  // and looks for the remaining characters if it is found
  int MyString::find(const char* pString) const {
    bool found = false;             // Sub-string found indicator

    // Search for the sub-string. We only need to look for
    // the first character up to the position where there is
    // enough room left for the sub-string to appear.
    for(unsigned int i = 0 ; i<strLength-strlen(pString)+1 ; i++)
      if(*(pStr+i) == *pString) {                 // If we find the first character
        found = true;
        for(unsigned int j = 1 ; j<strlen(pString) ; j++)  // look for the rest of the sub-string
          if(*(pStr+i+j) != *(pString+j)) {       // If any character doesn't match,
            found = false;                        // we didn't find it 
            break;                                // so go to next iteration in outer loop
          }
          if(found)                               // If we found it,
            return i;                             // Return the position,
      }
      return -1;                                  // otherwise return -1
  }

  // Find the occurrence of a MyString as a sub-string
  int MyString::find(const MyString& rString) const {
    return find(rString.pStr);                    // Just use the previous function to do it
  }

  // Display the string
  void MyString::show() const {
    if(strLength)
      cout << endl << pStr;
    else
      cout << endl << "String is empty.";
  }

  // Overloaded assignment operator
  MyString& MyString::operator=(const MyString& rhs) {
    if(this == &rhs)                      // Is lhs same object as rhs?
      return *this;                       // Yes, so just return it.

    // Objects are different so assign rhs to *this
    delete[] pStr;                        // Release memory for current string for *this object
    pStr = new char[rhs.strLength+1];     // Allocate space for string to be copied
    std::strcpy(pStr,rhs.pStr);           // Copy rhs string to lhs
    strLength = rhs.strLength;            // Set the length
    return *this;
  }

  // String concatenation
  // Operator must return a new object which is created as a local object 
  // A copy of the local object will be returned
  MyString MyString::operator+(const MyString& rhs) const {
    return MyString(*this) += rhs;
  }

  // Append MyString string
  // Operator returns a reference to the lhs
  // Uses the += operator for C-style strings to append the rhs string
  MyString& MyString::operator+=(const MyString& rhs) {
    return *this += rhs.pStr;  
  }

  // Append C-style string
  MyString& MyString::operator+=(const char* rhs) {
    char* pNewStr = new char[strLength+strlen(rhs)+1];   // Space for combined string
    std::strcpy(pNewStr,pStr);                           // Copy lhs string to new string
    std::strcpy(pNewStr+strLength,rhs);                  // Append rhs string to new string
    strLength += std::strlen(rhs);                       // Update length
    delete[] pStr;                                       // Release lhs string memory
    pStr = pNewStr;                                      // lhs string is new string
    return *this;                                        // Return lhs
  }

  // Subscript operator for const objects
  // Cannot be used on the left of an assignment as it return a const reference to char
  const char& MyString::operator[](int index) const {
    // These validity check would be better using exceptions to signal errors
    // rather than calling exit(). See Chapter 17
    if(strLength == 0) {
      cout << "\nString is empty in subscript operation. Program aborted.";
        exit(1);
    }
    if(strLength<index || index<0) {
      cout << "\nOut of range index in subscript operation. Program aborted.";
        exit(1);
    }

    if(index < strLength)
      return pStr[index];
  }

  // Subscript operator for non-const objects - can be used on the left of an assignment
  char& MyString::operator[](int index) {
    // These validity check would be better using exceptions to signal errors
    // rather than calling exit(). See Chapter 17
    if(strLength == 0) {
      cout << "\nString is empty in subscript operation. Program aborted.";
        exit(1);
    }
    if(strLength<index || index<0) {
      cout << "\nOut of range index in subscript operation. Program aborted.";
        exit(1);
    }

    if(index < strLength)
      return pStr[index];
  }

    // Overloaded 'equals' operator
  bool MyString::operator==(const MyString& rOperand) const {
    return (std::strcmp(pStr, rOperand.pStr) == 0);
  }

  // Overloaded 'not equals' operator
  bool MyString::operator !=(const MyString& rOperand) const {
    return (*this == rOperand);  
  }

  // Overloaded 'greater than' operator
  bool MyString::operator>(const MyString& rOperand) const {
    return (std::strcmp(pStr, rOperand.pStr) > 0);
  }

  // Overloaded 'less than' operator
  bool MyString::operator<(const MyString& rOperand) const {
    return (std::strcmp(pStr, rOperand.pStr) < 0);
  }

  // Overloaded function call operator
  // Returns a substring object - not a reference.
  // A copy of the local object will be returned.
  MyString MyString::operator()(int index, int length) const   {
    if(index<0 || index>strLength || index+length>strLength)     {
      cout << "\nOut of range in function call operator. Terminating program.";
      exit(1);
    }
    char* pSubStr = new char[length+1];           // Get space for substring

    for(int i = 0 ; i<length ; i++)               // Copy the substring
      pSubStr[i] = pStr[index+i];
    pSubStr[length] = '\0';                       // Append null character

    MyString tempStr(pSubStr);                    // Define a new object
    delete[] pSubStr;                             // Delete temporary string
    return tempStr;                               // Return the object
  }

}   // End of namespace mySpace;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
视频一区视频二区在线观看| 波多野结衣中文字幕一区| 久久99精品国产麻豆不卡| 国产电影一区在线| 欧美日韩成人一区| 国产精品久久网站| 久久精品久久99精品久久| 色婷婷激情综合| 国产视频一区在线播放| 老鸭窝一区二区久久精品| 91片黄在线观看| 国产日产亚洲精品系列| 蜜臀av性久久久久蜜臀aⅴ流畅| 色综合色综合色综合色综合色综合| 精品国产91乱码一区二区三区| 一区二区三区视频在线观看| 国产成人鲁色资源国产91色综| 91精品国产福利在线观看| 亚洲人成网站在线| 国产很黄免费观看久久| 精品区一区二区| 三级久久三级久久| 欧美日韩综合在线| 亚洲日本电影在线| 91在线视频播放| 国产精品大尺度| 99视频有精品| 亚洲私人黄色宅男| 色综合天天综合狠狠| 亚洲网友自拍偷拍| av在线播放成人| 中文在线免费一区三区高中清不卡| 韩国成人精品a∨在线观看| 日韩一二在线观看| 蜜臀精品一区二区三区在线观看 | 中文字幕精品一区二区精品绿巨人 | 国产成人综合在线观看| 久久午夜国产精品| 国产一区二区三区四区在线观看| 精品国产乱码久久久久久免费| 久久国产精品色| 久久免费看少妇高潮| 国产成人综合网| 一色屋精品亚洲香蕉网站| 99精品一区二区| 夜夜爽夜夜爽精品视频| 欧美私人免费视频| 亚洲高清免费观看高清完整版在线观看| 欧美影片第一页| 日韩黄色一级片| 久久综合成人精品亚洲另类欧美| 国内精品国产成人| 国产精品初高中害羞小美女文| 91影院在线免费观看| 午夜精品久久久久久久99水蜜桃| 91麻豆精品国产| 精品无人码麻豆乱码1区2区 | 日韩一区二区精品葵司在线| 久久99热狠狠色一区二区| 日本一区二区三区国色天香 | proumb性欧美在线观看| 亚洲一级二级三级| 精品国产露脸精彩对白| 成人黄色在线看| 午夜精品久久久久久久久久 | 国产成人午夜视频| 一区二区日韩av| 日韩女优毛片在线| 懂色av一区二区三区蜜臀| 亚洲精品国产精华液| 日韩欧美一二区| 97se亚洲国产综合自在线观| 天天亚洲美女在线视频| 国产精品免费视频观看| 欧美浪妇xxxx高跟鞋交| 懂色av一区二区夜夜嗨| 日韩va欧美va亚洲va久久| 国产精品毛片大码女人| 欧美一级生活片| 91啪在线观看| 国产乱人伦精品一区二区在线观看 | 自拍偷拍国产精品| 日韩欧美在线影院| 91视频国产观看| 狠狠久久亚洲欧美| 一区2区3区在线看| 国产欧美视频一区二区| 91精品国产一区二区| 91麻豆精东视频| 国产盗摄女厕一区二区三区 | 日韩欧美自拍偷拍| 日本韩国欧美在线| 成人三级伦理片| 久久成人av少妇免费| 五月激情丁香一区二区三区| 亚洲视频一二三区| 亚洲国产精品成人综合色在线婷婷| 日韩一级免费一区| 欧美日韩国产高清一区二区三区| 色吧成人激情小说| 97国产一区二区| 99re视频精品| 成人av一区二区三区| 国产精品资源网站| 国产呦精品一区二区三区网站| 日本sm残虐另类| 天堂成人国产精品一区| 亚洲aaa精品| 亚洲国产成人91porn| 亚洲福利视频三区| 亚洲主播在线观看| 有码一区二区三区| 亚洲精品国产精品乱码不99| 亚洲精品亚洲人成人网| 亚洲免费观看高清在线观看| 亚洲欧洲av色图| 亚洲欧美aⅴ...| 一区二区三区中文字幕精品精品 | 色综合色综合色综合色综合色综合| 成人av动漫网站| 99精品视频中文字幕| 91原创在线视频| 在线一区二区视频| 欧美性色欧美a在线播放| 欧美日韩精品一区二区在线播放 | 日韩欧美一区电影| 久久亚洲免费视频| 国产精品午夜在线| 中文幕一区二区三区久久蜜桃| 国产精品日日摸夜夜摸av| 亚洲日本在线观看| 午夜视频在线观看一区二区| 日本中文一区二区三区| 国产九色sp调教91| 成人av电影免费在线播放| 91久久精品一区二区| 日韩一区二区在线看片| 久久婷婷国产综合精品青草| 国产精品毛片a∨一区二区三区| 亚洲人成伊人成综合网小说| 午夜视黄欧洲亚洲| 国内成+人亚洲+欧美+综合在线| 国产高清不卡二三区| 在线日韩av片| 日韩精品中文字幕在线一区| 国产精品污网站| 亚洲最色的网站| 精品亚洲欧美一区| 色婷婷精品久久二区二区蜜臂av | 欧美日韩一区二区三区在线看| 9191久久久久久久久久久| 精品电影一区二区三区| ...中文天堂在线一区| 日日摸夜夜添夜夜添精品视频| 国产伦理精品不卡| 欧美在线观看一二区| 亚洲精品在线网站| 亚洲午夜影视影院在线观看| 九九久久精品视频| 欧美在线观看一区| 国产三级精品三级| 日韩激情一二三区| 99精品国产热久久91蜜凸| 欧美一区二区视频在线观看| 国产精品久久久久久久久快鸭 | 日韩精品专区在线影院重磅| 亚洲男人都懂的| 国产精品18久久久久久久久| 555夜色666亚洲国产免| 国产精品美女久久久久久久| 看电视剧不卡顿的网站| 在线免费亚洲电影| 国产欧美日韩卡一| 黄色资源网久久资源365| 欧美剧情片在线观看| 中文字幕在线不卡一区二区三区| 久久精品国产色蜜蜜麻豆| 欧美三区免费完整视频在线观看| 日本一区二区高清| 激情五月激情综合网| 91精品国产综合久久精品性色| 亚洲欧美精品午睡沙发| 粉嫩嫩av羞羞动漫久久久| 欧美不卡视频一区| 日韩福利电影在线观看| 欧美日韩在线三区| 一区二区三区四区高清精品免费观看 | 亚洲h在线观看| 在线免费观看不卡av| 综合激情成人伊人| 成人丝袜视频网| 国产欧美va欧美不卡在线| 国产不卡在线视频| 国产欧美日韩综合| 成人av资源下载| 亚洲欧美综合色| 91色.com| 亚洲国产aⅴ天堂久久| 欧美日韩视频一区二区| 午夜视频一区二区三区|