U E D R , A S I H C RSS

Our Major Lang IsCAndCPlus Plus/2006.2.06/허준수

~cpp
#include <iostream> 
#include <cstring> 
#include <cstdlib> 

using namespace std; 

class myString{ 
private: 
    //char* ch; 

public: 
    char* ch; 

    myString() { 
        ch = NULL; 
    }; 

    myString(const char* ch) { 
        this->ch = new char[strlen(ch)+1]; 
        strcpy(this->ch, ch); 
        //this->ch = ch; 
    }; 

	myString(const myString& s) {
		this->ch = new char[strlen(s.ch)+1];
		strcpy(this->ch, s.ch);
	};

    ~myString() { 
        delete [] ch; 
    }; 

    int length() const { 
        int  temp = strlen(ch); 
        return temp; 
    }; 

	void operator = (const myString& s) {
		this->ch = new char[strlen(s.ch)+1];
		strcpy(this->ch, s.ch);
	};
    
	char& operator[] (int n) {
		return *(ch+n);
	};
    //friend ostream& operator << (ostream& o, myString &s); 
}; 

ostream& operator << (ostream& o, const myString& s) { 
    o << s.ch; 
    return o; 
} 

istream& operator >> (istream& i, myString& s) {
	if(s.ch==NULL)
		delete[] s.ch;
	s.ch = new char[255];
	i >> s.ch;
	return i;
}


int main() 
{ 
	myString s = "12345";
	cout << s[2] << endl;
	s[2] = 'x';
	cout << s<<endl;
	/*myString s1, s2;
	s1 = "123";
	s2 = s1;
	cout << s1 << s2;
	/*myString s1 = "123", s2;
	s2 = s1;
	cout << s1 << s2;
	/*myString s1, s2;
	s1 = "123";
	s2 = s1;
	cout << s1 << s2 <<endl;
	/*myString s1 = "123";
	myString s2 = s1;
	cout << s2;
    /*const myString s = "123"; 
	myString s2 = "4567";
    cout << s << s.length() << endl; 
	cout << s2 <<endl;	
	/*myString s;
	cout << "string? : ";
	cin >> s;
	cout << "input string : " << s <<endl;
    */
    
    return 0; 
} 
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0069 sec