📄 mystr.cpp
字号:
// MyStr.cpp: implementation of the MyStr class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MyStr.h"
#include "string.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
MyStr::MyStr()
{
this->m_pStr = NULL;
}
MyStr MyStr::operator =(MyStr& str)
{
delete []this->m_pStr;
char *p = str.m_pStr;
if(p)
{
int n = strlen(p);
m_pStr = new char[n+1];
strcpy(m_pStr, str.m_pStr);
}
else
m_pStr = NULL;
return *this;
}
MyStr::MyStr(MyStr &str)
{
char *p = str.m_pStr;
if(p)
{
int n = strlen(p);
m_pStr = new char[n+1];
strcpy(m_pStr, str.m_pStr);
}
else
m_pStr = NULL;
}
MyStr::MyStr(char *p)
{
int n = strlen(p);
m_pStr = new char[n+1];
strcpy(m_pStr, p);
}
MyStr::~MyStr()
{
delete []m_pStr;
}
#define MaxSize 256
istream & operator >>( istream & input, MyStr& str)
{
char s[MaxSize];
input >> s;
int n = strlen(s);
str.m_pStr = new char[n+1];
strcpy(str.m_pStr, s);
return input;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -