Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstddef>
- using size = std::size_t;
- using byte = std::uint8_t;
- using ByteVector = std::vector<byte>;
- struct String {
- private:
- ByteVector bytes;
- public:
- ByteVector& Bytes() { return bytes; };
- size Capacity() const { return bytes.capacity(); }
- size Total() const { return bytes.size(); }
- byte& Get(const size index) { return bytes[index]; }
- void Reserve(const size capacity) { bytes.reserve(capacity); }
- void Resize(const size total) { bytes.resize(total); }
- void Push(String string) {
- bytes.reserve(bytes.size() + string.Total());
- for (size index = 0; index < string.Total(); index += 1) {
- bytes[bytes.size() + index] = string.Get(index);
- }
- }
- String() { bytes = ByteVector(); }
- String(const char* string) {
- bytes = ByteVector(strlen(string));
- for (size index = 0; index < bytes.size(); index += 1) {
- bytes[index] = *(string + index);
- }
- }
- };
- std::ostream& operator <<(std::ostream& out, String& string) {
- for (size index = 0; index < string.Capacity(); index += 1)
- out << string.Get(index);
- return out;
- }
- int main(int argc, char** argv) {
- String string("Hello world!");
- string.Push(String(" This is my custom string."));
- std::cout << string << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement