Mega Code Archive

 
Categories / C++ / Overload
 

String class with custom +- operator

#include <iostream> #include <iomanip> #include <string.h> using namespace std; class String  {   public:      char *operator +(char *append_str)     { return(strcat(buffer, append_str)); };         char *operator -(char letter);     String(char *string)      { strcpy(buffer, string);          length = strlen(buffer);      }     void show_string() { cout << buffer; };   private:     char buffer[256];     int length; }; int main(void){    String title("A");    title = title + "Programmer's Bible\n";    title.show_string(); }