1、string仿写头函数(Mystring.h):
//#pragma once
#ifndef _MYSTRING
#define _MYSTRING
#include<iostream>
using namespace std;
class stu
{
private:
char* m_str;
size_t m_l;
public:
stu();
stu(size_t length ,char ch);
stu(const char* str);
stu(const char* str,size_t length);
stu(stu& str,size_t index,size_t length);
stu(const stu& str);
public:
const char* c_str() const;
const char* size() const;
public:
~stu();
};
#endif
2、主函数(main.cpp):
#include "Mystring.h"
int main()
{
stu str;
stu str1(5,'b');
cout << str1.c_str()<<endl;
stu str2("abcdef");
cout << str2.c_str() << endl;
stu str3("abcdefghehasdj",7);
cout << str3.c_str() << endl;
stu str4(str3,2,5);//[2,5)
cout << str4.c_str() << endl;
stu str5(str3);
cout << str5.c_str() << endl;
system("pause");
return 0;
}