FMI Table
| Kamen Mladenov | FMI Computer Science Year 1 Group 6 | Project 2 | Project Topic 7 |
String.h
Go to the documentation of this file.
1#ifndef HEADER_STRING
2#define HEADER_STRING
3
8#include <istream>
9#include <ostream>
10
11#define DOUBLE_PRECISION 100
12
17class String {
18 char* str;
19 unsigned length;
20
21 void free();
22 void copyFrom(const String& other);
23
24public:
26 String(unsigned length);
28 String(const char* str);
30 const char* get_cstr() const;
32 unsigned get_length() const;
34 char& operator[](unsigned index);
35
37 String& operator+=(const char* str);
39 String& operator+=(int number);
41 String& operator+=(unsigned number);
43 String& operator+=(double number);
44
45 String();
46 String(const String& other);
47 String& operator=(const String& other);
48 ~String();
49
50 String(String&& other);
51 String& operator=(String&& other);
52
54 void read(std::istream& istr);
56 void write(std::ostream& ostr) const;
58 int compare(const String& other) const;
59
61 friend std::istream& operator>>(std::istream& istr, String& str);
63 friend std::ostream& operator<<(std::ostream& ostr, const String& str);
64};
65
66#endif
A dynamically-allocated C-style string with extra features.
Definition: String.h:17
friend std::istream & operator>>(std::istream &istr, String &str)
Reads String from stream with >> operator.
Definition: String.cpp:177
const char * get_cstr() const
Returns internal C-style string.
Definition: String.cpp:35
int compare(const String &other) const
Compares two strings.
Definition: String.cpp:167
char & operator[](unsigned index)
Returns a character reference (from the underlying C-style string) at the given index.
Definition: String.cpp:43
String & operator+=(const char *str)
Appends a C-style string.
Definition: String.cpp:49
unsigned get_length() const
Returns number of characters in string.
Definition: String.cpp:39
void write(std::ostream &ostr) const
Writes String to stream.
Definition: String.cpp:159
friend std::ostream & operator<<(std::ostream &ostr, const String &str)
Writes String to stream with << operator.
Definition: String.cpp:189
void read(std::istream &istr)
Reads String from stream.
Definition: String.cpp:146