diff options
Update MyString.cpp
1 files changed, 22 insertions, 1 deletions
| -rw-r--r-- | Sem. 10/Examples/MyString/MyString.cpp | 23 |
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 +} |
