百度试题 题目基于char*设计一个字符串类MyString,并且具有构造函数、析构函数、复制构造函数,重载运算符“+”、“=”、“+=”、“[]”,尽可能完善它,使之能满足各种需要。相关知识点: 试题来源: 解析反馈 收藏
char* c_str() const { return m_data; } private: char* m_data; friend ostream& operator << (ostream&os, const MyString& str); friend istream& operator >> (istream&is, MyString& str); }; 类的实现文件: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
private:char * str;int len;};//MStr.cpp include "MStr.h"include MStr::MStr(void){ str = new char;str[0] = '\0';len = 0;} MStr::MStr(char *s){ int size = strlen(s);str = new char[size+1];str[size] = '\0';strcpy(str,s);len = size;} MStr::MStr(const...
pragma once#include<iostream>using namespace std;class MStr{public:MStr(void);~MStr(void);//析构函数MStr(char *);MStr(const MStr&);//复制构造函数const MStr operator +(const MStr &);//重载加法friend ostream & operator <<(ostream &, const MStr &);//重载输出流friend istream...