Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //string.cpp
- using namespace std;
- #include <iostream>
- #include "/user/cse232/Projects/project07.string.h"
- // Return string capacity and length
- //
- // Destroy string
- //
- String::~String(){
- Capacity=0;
- Length=0;
- delete Mem;
- Mem=NULL;
- }
- // Construct string by copying existing string
- //
- String::String( const String& Sin){
- Capacity=Sin.Capacity;
- Length=Sin.Length;
- Mem=Sin.Mem;
- }
- // Construct string by copying C-style character string
- //
- String::String( const char cstr[]){
- //cout<<"ohhello"<<endl;
- // cout<<"size of c "<<sizeof(char)<<endl;
- /* while(sizeof(cstr)>Capacity){
- cout<<"in while"<<endl;
- Capacity++;
- }
- for(unsigned idx=0;idx<sizeof(cstr);idx++){
- cout<<"in for"<<endl;
- Mem[idx]=cstr[idx];
- }*/
- }
- // Copy string into the current string
- //
- String& String::operator=( const String& Sin){
- reset();
- Capacity=Sin.Capacity;
- Length=Sin.Length;
- Mem=Sin.Mem;
- return *this;
- }
- // Append string to the current string
- //
- String& String::operator+=( const String& Sin){
- while(Length+Sin.length()<Capacity){
- Capacity+=16;
- }
- unsigned idx2=0;
- for(unsigned idx=Length;idx<(Length+Sin.length());idx++){
- idx2++;
- Mem[idx]=Sin[idx2];
- }
- Length=Length+Sin.length();
- return *this;
- }
- // Return string which is the concatenation of two strings
- //
- //String operator+( const String&, const String& ){
- //return NULL;
- //}
- // Compare two strings (equality and relational operators)
- //
- //bool operator==( const String&, const String& );
- //bool operator< ( const String&, const String& );
- // Output string to stream
- //
- //ostream& operator<<( ostream&, const String& );
- // Input string from stream
- //
- //istream& operator>>( istream&, String& );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement