环境配置
codeblocks
windows10
项目结构
代码
LinkStringClass.h
#ifndef _LINKSTRINGCLASS_H_
#define _LINKSTRINGCLASS_H_
#include <iostream>
class LinkStringNode
{
public:
char data;
LinkStringNode *next;
};
class LinkStringClass
{
public:
/* 构造函数, 析构函数 */
LinkStringClass(void);
explicit LinkStringClass(const char *const str);
explicit LinkStringClass(const LinkStringClass &str);
~LinkStringClass(void);
/* 成员函数 */
int StringLength(void) const;
LinkStringClass &StrIns(int i, const char *const str);
LinkStringClass &StrIns(int i, const LinkStringClass &str) const;
LinkStringClass &StrDel(int i, int len) const;
LinkStringClass &StrSub(int i, int len) const;
LinkStringClass &StrRep(int i, int len, const char *const str) const;
LinkStringClass &StrRep(int i, int len, const LinkStringClass &str) const;
void Display(void) const;
void Clean(void) const;
/* 成员运算符重载 */
LinkStringClass &operator=(const char *const str);
LinkStringClass &operator=(const LinkStringClass &str);
LinkStringClass &operator+(const char *const str) const;
LinkStringClass &operator+(const LinkStringClass &str) const;
char &operator[](int i) const;
operator char *(void) const;
/* 友元运算符重载 */
friend std::istream &operator>>(std::istream &in, LinkStringClass &s);
friend std::ostream &operator<<(std::ostream &out, const LinkStringClass &s);
protected:
private:
LinkStringNode *head;
};
std::istream &operator>>(std::istream &in, LinkStringClass &s);
std::ostream &operator<<(std::ostream &out, const LinkStringClass &s);
#endif // _LINKSTRINGCLASS_H_
LinkStringClass.cpp
#include "LinkStringClass.h"
using namespace std;
LinkStringClass::LinkStringClass(void)
{
head = new LinkStringNode;
head->next = nullptr;
}
LinkStringClass::Li