From 8f090e1bb33558b4ad7591bb36e4697530ba75bb Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 3 May 2022 20:43:28 +0300 Subject: Update MyString.cpp --- Sem. 10/Examples/MyString/MyString.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'Sem. 10/Examples/MyString/MyString.cpp') diff --git a/Sem. 10/Examples/MyString/MyString.cpp b/Sem. 10/Examples/MyString/MyString.cpp index 77f2119..8290dd0 100644 --- a/Sem. 10/Examples/MyString/MyString.cpp +++ b/Sem. 10/Examples/MyString/MyString.cpp @@ -20,6 +20,27 @@ MyString::MyString() size = 0; } +size_t getNumSize(size_t num) +{ + size_t res = 0; + while(num) + { + res++; + num/=10; + } +} +MyString(size_t n) +{ + int numSize = getNumSize(n); + str = new char[numSize + 1]; + + str[numSize] = '\0'; + + for(size_t i = 0; i < numSize; i++, n/=10) + str[numSize - 1 - i] = (n % 10) + '0'; + size = numSize; +} + MyString::MyString(const char* data) { size = strlen(data); @@ -135,4 +156,4 @@ MyString& MyString::operator=(MyString&& otherString) size = otherString.size; } return *this; -} \ No newline at end of file +} -- cgit v1.3.1-23-gd82d