Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. //string.cpp
  2. using namespace std;
  3.  
  4. #include <iostream>
  5. #include "/user/cse232/Projects/project07.string.h"
  6.  
  7.  
  8.     // Return string capacity and length
  9.     //
  10.    
  11.     // Destroy string
  12.     //
  13.     String::~String(){
  14.         Capacity=0;
  15.         Length=0;
  16.         delete Mem;
  17.         Mem=NULL;
  18.     }
  19.     // Construct string by copying existing string
  20.     //
  21.     String::String( const String& Sin){
  22.         Capacity=Sin.Capacity;
  23.         Length=Sin.Length;
  24.         Mem=Sin.Mem;
  25.     }
  26.  
  27.     // Construct string by copying C-style character string
  28.     //
  29.     String::String( const char cstr[]){
  30. //cout<<"ohhello"<<endl;
  31. //  cout<<"size of c    "<<sizeof(char)<<endl;
  32. /*      while(sizeof(cstr)>Capacity){
  33.     cout<<"in while"<<endl;
  34.             Capacity++;
  35.         }
  36.         for(unsigned idx=0;idx<sizeof(cstr);idx++){
  37.             cout<<"in for"<<endl;
  38.             Mem[idx]=cstr[idx];
  39.     }*/
  40.     }
  41.  
  42.     // Copy string into the current string
  43.     //
  44.     String& String::operator=( const String& Sin){
  45.         reset();
  46.         Capacity=Sin.Capacity;
  47.         Length=Sin.Length;
  48.         Mem=Sin.Mem;
  49.         return *this;
  50.     }
  51.  
  52.     // Append string to the current string
  53.     //
  54.     String& String::operator+=( const String& Sin){
  55.         while(Length+Sin.length()<Capacity){
  56.         Capacity+=16;
  57.         }
  58.         unsigned idx2=0;
  59.         for(unsigned idx=Length;idx<(Length+Sin.length());idx++){
  60.             idx2++;
  61.             Mem[idx]=Sin[idx2];
  62.         }
  63.         Length=Length+Sin.length();
  64.         return *this;
  65.     }
  66.  
  67. // Return string which is the concatenation of two strings
  68. //
  69. //String operator+( const String&, const String& ){
  70. //return NULL;
  71. //}
  72.  
  73. // Compare two strings (equality and relational operators)
  74. //
  75. //bool operator==( const String&, const String& );
  76. //bool operator< ( const String&, const String& );
  77.  
  78. // Output string to stream
  79. //
  80. //ostream& operator<<( ostream&, const String& );
  81.  
  82. // Input string from stream
  83. //
  84. //istream& operator>>( istream&, String& );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement