aboutsummaryrefslogtreecommitdiff
path: root/week10/Exercise10
diff options
context:
space:
mode:
Diffstat (limited to 'week10/Exercise10')
-rw-r--r--week10/Exercise10/ShowableString.cpp10
-rw-r--r--week10/Exercise10/ShowableString.h2
2 files changed, 8 insertions, 4 deletions
diff --git a/week10/Exercise10/ShowableString.cpp b/week10/Exercise10/ShowableString.cpp
index 1231a9c..09dbd51 100644
--- a/week10/Exercise10/ShowableString.cpp
+++ b/week10/Exercise10/ShowableString.cpp
@@ -1,9 +1,13 @@
#include "ShowableString.h"
std::ostream& operator<<(std::ostream& ostr, const ShowableString& str) {
- return ostr << str;
+ return ostr << str.str;
}
-std::istream& operator>>(std::istream& istr, const ShowableString& str) {
- return istr >> str; // Лошо!
+std::istream& operator>>(std::istream& istr, ShowableString& str) {
+ unsigned size;
+ istr >> size;
+ str.free();
+ str.str = new char[size];
+ return istr >> str.str;
}
diff --git a/week10/Exercise10/ShowableString.h b/week10/Exercise10/ShowableString.h
index ff46f6c..6bf02e6 100644
--- a/week10/Exercise10/ShowableString.h
+++ b/week10/Exercise10/ShowableString.h
@@ -5,5 +5,5 @@
class ShowableString : ModifiableString {
public:
friend std::ostream& operator<<(std::ostream& ostr, const ShowableString& str);
- friend std::istream& operator>>(std::istream& istr, const ShowableString& str);
+ friend std::istream& operator>>(std::istream& istr, ShowableString& str);
};