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

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

?? mystring.cpp

?? 一本語言類編程書籍
?? CPP
字號:
// Exercise 14.3 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];
  }

}   // End of namespace mySpace;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99国内精品久久| 成人av中文字幕| 图片区小说区区亚洲影院| 亚洲精品视频在线观看网站| 亚洲欧美在线视频| 亚洲免费资源在线播放| 亚洲精品视频在线| 亚洲成人资源网| 偷拍一区二区三区四区| 日韩精品电影在线观看| 日韩电影免费在线| 国产美女视频一区| 成人动漫一区二区在线| 色香蕉久久蜜桃| 欧美日韩另类一区| 欧美精品一区二区三区蜜桃 | 一区二区三国产精华液| 亚洲激情中文1区| 视频一区欧美精品| 经典三级一区二区| 99视频一区二区| 精品视频免费看| 欧美成va人片在线观看| 日本一区二区三区四区在线视频 | 亚洲最大成人网4388xx| 五月婷婷激情综合| 国产成人在线免费| 在线区一区二视频| 精品国产乱码久久久久久影片| 国产视频一区二区在线观看| 亚洲精品视频在线看| 另类欧美日韩国产在线| kk眼镜猥琐国模调教系列一区二区| 色欧美88888久久久久久影院| 欧美日韩成人综合在线一区二区| 精品久久久久av影院 | 欧美理论片在线| 久久久久免费观看| 亚洲精品欧美在线| 精一区二区三区| 色噜噜夜夜夜综合网| 精品免费视频一区二区| 亚洲视频1区2区| 韩国欧美国产一区| 欧美色综合网站| 国产精品久久久久久久久久免费看| 亚洲国产成人高清精品| eeuss国产一区二区三区| 欧美一二三四区在线| 亚洲精品欧美二区三区中文字幕| 国产一区二区精品久久91| 欧美精品日韩精品| 亚洲激情在线激情| av高清久久久| 欧美激情一区二区三区蜜桃视频| 亚洲成人免费电影| 91精品办公室少妇高潮对白| 国产天堂亚洲国产碰碰| 天堂va蜜桃一区二区三区漫画版| 色综合夜色一区| 日韩美女久久久| 成人一区二区三区视频在线观看| 欧美成人a视频| 久久精品国产99国产| 日韩一级二级三级| 奇米888四色在线精品| 欧美日韩一卡二卡三卡| 亚洲男人电影天堂| 色菇凉天天综合网| 一区二区三区在线视频免费| 99久久精品国产一区| 国产精品欧美综合在线| 国产jizzjizz一区二区| 久久夜色精品国产噜噜av| 美女一区二区三区在线观看| 欧美一区二区性放荡片| 日本伊人色综合网| 日韩欧美精品在线| 久久99九九99精品| 久久久美女艺术照精彩视频福利播放| 男人的天堂亚洲一区| 日韩一级完整毛片| 狠狠色2019综合网| 亚洲国产成人一区二区三区| 粉嫩av一区二区三区粉嫩| 国产精品久线在线观看| 91免费国产在线观看| 亚洲一区影音先锋| 欧美一区二区二区| 国产大陆亚洲精品国产| 国产精品国产三级国产普通话蜜臀 | 亚洲精品在线电影| 国产成人在线视频网址| 亚洲欧美日韩在线| 欧美高清你懂得| 激情五月激情综合网| 亚洲国产高清不卡| 欧美色图片你懂的| 精品一区二区成人精品| 国产精品久久久久久户外露出| 色综合一区二区| 美女mm1313爽爽久久久蜜臀| 日本一区二区三区国色天香| 一本大道av一区二区在线播放| 亚洲777理论| 精品精品国产高清a毛片牛牛| 成人爽a毛片一区二区免费| 免费在线观看成人| 国产精品美女久久久久久久久久久 | 欧美国产精品一区二区| 91麻豆蜜桃一区二区三区| 亚洲丶国产丶欧美一区二区三区| 日韩免费一区二区| 一本一本大道香蕉久在线精品| 午夜国产不卡在线观看视频| 国产女人aaa级久久久级| 欧美人伦禁忌dvd放荡欲情| 国产成a人亚洲精品| 日韩精品成人一区二区在线| 日本一区二区三级电影在线观看| 欧美日韩一区二区三区在线看 | 亚洲免费看黄网站| 精品粉嫩aⅴ一区二区三区四区| 91视视频在线直接观看在线看网页在线看| 亚洲成a人在线观看| 国产精品久久久久久久久晋中 | 亚洲免费视频中文字幕| 久久网这里都是精品| 欧美色国产精品| 国产v日产∨综合v精品视频| 日产精品久久久久久久性色 | 欧美片网站yy| 成人高清伦理免费影院在线观看| 日本强好片久久久久久aaa| 国产精品久久久久影院亚瑟| 26uuu国产电影一区二区| 欧美巨大另类极品videosbest| 91亚洲精华国产精华精华液| 成人黄页毛片网站| 国产一区高清在线| 美女视频黄 久久| 日本不卡123| 五月天网站亚洲| 亚洲国产成人av好男人在线观看| 国产精品美女视频| 国产精品初高中害羞小美女文| 久久综合九色综合97婷婷女人| 欧美精品日韩综合在线| 欧美日本在线视频| 91精品国产日韩91久久久久久| 成人激情小说网站| 波多野结衣在线一区| 成人在线一区二区三区| 成人激情电影免费在线观看| 成人激情av网| 色av一区二区| 欧美在线制服丝袜| 欧美日韩一区中文字幕| 欧美日韩成人激情| 777久久久精品| 欧美va天堂va视频va在线| 欧美高清一级片在线| 欧美一三区三区四区免费在线看| 欧美一二三在线| 国产午夜精品美女毛片视频| 国产精品无码永久免费888| 国产精品麻豆久久久| 亚洲免费毛片网站| 亚洲成人tv网| 国产精品自拍一区| 波多野结衣精品在线| 欧美中文一区二区三区| 欧美精品三级日韩久久| 久久日韩粉嫩一区二区三区| 国产精品免费看片| 亚洲成人激情av| 国产麻豆精品在线观看| 91在线小视频| 在线成人高清不卡| 国产视频一区在线播放| 亚洲精品欧美综合四区| 美女视频第一区二区三区免费观看网站| 精品无人码麻豆乱码1区2区| 91视频你懂的| 欧美一区二区精品久久911| 亚洲国产岛国毛片在线| 日韩成人伦理电影在线观看| 国产精品一区免费在线观看| 日本精品视频一区二区| 日韩区在线观看| 亚洲男人的天堂在线观看| 99热国产精品| 欧美精品丝袜中出| 国产精品欧美久久久久无广告 | 在线播放视频一区| 亚洲国产精品v| 老司机免费视频一区二区| www.欧美.com| 日韩午夜激情电影| 亚洲综合免费观看高清完整版在线|