DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Quoc Bao
Quoc Bao

Posted on • Updated on

String class implementation

Hello everybody! Today, I would like to show you a quick implementation of a string class.

A string is an array of characters. So, we initialize it with an array of char type and a length.

class STRING
{
private:
    char *content;
    int len;

    void deepcopy(const STRING &other);

public:
    STRING();
    // ~STRING();
    STRING(std::string);

    STRING(const STRING &other);
    STRING &operator=(const STRING &other);

    bool operator==(STRING &other);
    bool operator==(std::string);
    bool operator!=(STRING other);

    char getContent(int);
    char *getWholeContent();
    void deleteContent();
    void allocateContent(int);
    int getLen();
    void setLen(int);
    void setContent(int, char);

    void input();
    void output();

    void removeBlankHead();
    void removeBlankTail();
    void RemoveExtraSpaces();

    friend std::istream &operator>>(std::istream &in, STRING &a);
    friend std::ostream &operator<<(std::ostream &out, STRING a);
};
Enter fullscreen mode Exit fullscreen mode

Read more here!

Top comments (0)

We are hiring! Do you want to be our Senior Platform Engineer? Forem is hiring a Senior Platform Engineer

If you're interested in ops and site reliability and capable of dipping in to our Linux stack, we'd love your help shoring up our systems!