From 8648ab3152c1e821e46830f62e31f76d2516d42d Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 14 Oct 2024 10:09:14 -0700 Subject: [PATCH] Added operator= integer operator. --- MString.cpp | 10 +++++++++- MString.h | 6 ++++++ testing/mstring_test.cpp | 7 ++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/MString.cpp b/MString.cpp index 7f7258f..e7e8dde 100644 --- a/MString.cpp +++ b/MString.cpp @@ -139,7 +139,15 @@ namespace coreutils { cursor = this->data; return *this; } - + + MString &MString::operator=(int value) { + std::string temp = std::format("{}", value); + setSize(temp.length()); + memcpy(this->data, (char *)temp.data(), temp.length()); + cursor = this->data; + return *this; + } + MString &MString::operator<<(const char *value) { int temp = length; int len = strlen(value); diff --git a/MString.h b/MString.h index 52b8ef4..e24d22e 100644 --- a/MString.h +++ b/MString.h @@ -129,6 +129,12 @@ namespace coreutils { MString &operator=(double value); + /// + /// Assignment operator for saving an integer value.. + /// + + MString &operator=(int value); + /// /// /// diff --git a/testing/mstring_test.cpp b/testing/mstring_test.cpp index 7f1590d..47e0596 100644 --- a/testing/mstring_test.cpp +++ b/testing/mstring_test.cpp @@ -88,7 +88,12 @@ int main(int argc, char **argv) { coreutils::MString test26; double test27 = 4.0f; test26 = test27; - std::cout << "float: " << test26 << std::endl; + std::cout << "float: " << test26 << std::endl; + + coreutils::MString test28; + int test29 = 402; + test28 = test29; + std::cout << "int: " << test28 << std::endl; return 0; }