FMI Ticket System
| Kamen Mladenov | FMI Computer Science Year 1 Group 6 | Project 1 | Project Topic 4 |
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
11class String {
12 char* str;
13 unsigned length;
14
15 void free();
16 void copyFrom(const String& other);
17
18public:
20 String(unsigned length);
22 String(const char* str);
24 const char* get_cstr() const;
26 unsigned get_length() const;
28 char& operator[](unsigned index);
29
31 String& operator+=(const char* str);
33 String& operator+=(unsigned number);
34
35 String();
36 String(const String& other);
37 String& operator=(const String& other);
38 ~String();
39
40 String(String&& other);
41 String& operator=(String&& other);
42
44 void read(std::istream& istr);
46 void write(std::ostream& ostr) const;
48 int compare(const String& other) const;
49
51 friend std::istream& operator>>(std::istream& istr, String& event);
53 friend std::ostream& operator<<(std::ostream& ostr, const String& event);
54};
55
56#endif
Definition: String.h:11
friend std::istream & operator>>(std::istream &istr, String &event)
Reads String from stream with >> operator.
Definition: String.cpp:153
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:143
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:135
friend std::ostream & operator<<(std::ostream &ostr, const String &event)
Writes String to stream with << operator.
Definition: String.cpp:165
void read(std::istream &istr)
Reads String from stream.
Definition: String.cpp:122