Actually the task itself sounds like this:
Create a class string that should contain the following information: the length of the string, the number of bytes that the string occupies. The class must have a destructor, a default constructor and a constructor with a parameter (Allocate memory for a line in blocks of a given length).
Write a method of combining strings, the result should contain only those characters that are in the first line and not in the second, followed by the characters of the second line which are not in the first.
It seems like I was able to deal with the allocation of memory, but then I got stuck and do not understand what to do.
Here is the code:
#include <iostream> #include <string.h> using namespace std; class String { private: char *_string; uint32_t memlen, step, len; public: String():_string(new char[0]), memlen(0), step(10), len(0){} String(const char *str, int step = 10) { if (step > 0) this -> step = step; else this -> step = 16; len = strlen(str); cout << this -> len << endl; memlen = step * ((len + step) / step); this -> _string = new char[memlen]; strcpy(_string, str); } ~String() { delete [] _string; } // ΠΏΡΠΎΠ²Π΅ΡΠΊΠ°, ΡΠ°Π±ΠΎΡΠ°Π΅Ρ Π»ΠΈ Π²ΡΠ΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΏΠ°ΠΌΡΡΠΈ void show() { for(uint32_t i=0; i<len; i++) cout<<_string[i]; cout<<endl; } }; int main() { String s("Hello World!"); s.show(); return 0; }