String.h
#pragma once #include <iostream> using namespace std; #include <string.h> class String { friend ostream& operator<<(ostream& out, String& obj); friend istream& operator>>(istream& in, String& obj); friend bool operator <(const String& left, const String& right); friend bool operator >(const String& left, const String& right); friend bool operator ==(const String& left, const String& right); friend bool operator !=(const String& left, const String& right); public: String(); String(int n, char c); String(const char* source); String(const String& obj); String& operator=(char* s); String& operator=(const String& obj); ~String(); char& operator[](int i); const char& operator[](int i)const; String& operator+=(const String& obj); String& operator+=(const char* s); char* getData() { return data; } int length() { return size; } private: int size; char* data; };
String.cpp
#include "stdafx.h" #include "String.h" String::String() { data = new char[1]; *data = '