#include "MyString.h" #include MyString::MyString() { cout << "<>\n"; this->str = new char('\0'); }; MyString::MyString(const char* value) { cout << "<>\n"; this->str = new char[strlen(value) + 1]; strcpy_s(str, strlen(value) + 1, value); this->str[strlen(value)] = '\0'; }; MyString::MyString(const MyString& obj) { cout << "<>\n"; this->str = new char[strlen(obj.str) + 1]; strcpy_s(str, strlen(obj.str) + 1, obj.str); this->str[strlen(obj.str)] = '\0'; }; MyString::~MyString() { cout << "<>\n"; delete[] this->str; }; char* MyString::getString() { cout << "<\n"; return this->str; }; void MyString::set(const char* value) { cout << "<>\n"; delete[] this->str; this->str = new char[strlen(value) + 1]; strcpy_s(str, strlen(value) + 1, value); this->str[strlen(value)] = '\0'; }; void MyString::print() { cout << "<>\n"; cout << this->str << endl; }; void MyString::update() { cout << "<>\n"; writeToFile(); if (strlen(this->str) % 2 != 0) { int middleIndex = strlen(this->str) / 2; for (size_t i = middleIndex; i < strlen(this->str); i++) { this->str[i] = this->str[i+1]; } this->str[strlen(this->str)] = '\0'; writeToFile(); } }; void MyString::writeToFile() { cout << "<>\n"; ofstream MyFile("filename.txt", ios_base::app); MyFile << this->str << "\n"; MyFile.close(); };