#include #include #include #include #include using namespace std; struct DynamicStr{ char* str; unsigned int len; DynamicStr(){ str=NULL; len = 0; } DynamicStr(char *newstr){ str = NULL; len = 0; SetStr(newstr); } unsigned int GetLength(){ return len; } void SetStr(char* newstr) { //Если строка была уже инициализирована ранее то очищаем занимаемую ей память if (str!=NULL){ delete[] str; } if (newstr==NULL) { str = NULL; len = 0; } //Определяем длину строки int i = 0; while (newstr[i]!='\0') i++; //Создаем динамическую строку len = i; str = new char[len+1]; //Копируем символы из передаваемой строки в строку структуры for (i=0; istr!=NULL){ for(;istr; } //Переносим символы их присоединяемой строки в новую строку for (int k = 0;kstr = newstr; len = constrlen+len; } //Функция поиска подстроки в строе int StrPos(char* findstr){ char* x = strstr(this->str,findstr); if (x!=NULL) return x-this->str+1; else return -1; } //Функция удаления подстроки из строки void DeleteStr(char *_src) { if (_src==NULL) return; char* t; do{ t=strstr (this->str, _src); if (t!=NULL) { char* t_ = t + strlen (_src); strcpy (t, t_); } else break; } while (true); } //Перегружаем оператор присваивания DynamicStr& operator=(const DynamicStr& right) { this->SetStr(right.str); return *this; } //Перегружаем оператор сложения const DynamicStr& operator+(const DynamicStr& right){ DynamicStr(this->str); } //Вывод строки в поток friend ostream &operator<<(ostream & output, const DynamicStr &x) { output<>otvet; fflush(stdin); switch(otvet){ case 1: { char* tmp = new char[255]; cout<<"Введите строку:"; cin.getline(tmp,255); s.SetStr(tmp); cout<<"Строка установлена."<