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!

Latest comments (0)

DEV

Thank you.

Β 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.