class String{
private:
char* m_Buffer;
unsigned int m_Size;
public:
String(const char* string){//首先const char* 等同于string
m_Size=int(strlen(string));//因为64位的strlen是unisigned long
m_Buffer=new char[m_Size+1];
memcpy(m_Buffer,string,m_size);
m_Buffer[m_Size]=0;
}
friend std::ostream& operator<<(std::ostream& stream,const String& string);
};
std::ostream& operator<<(std::ostream& stream,const String& string){
stream<<string.m_Buffer;
return stream;
}
int main(){
String string="wkx";
std::cout<<string<<std::endl;
std::cin.get();
}
标签:const,string,Buffer,char,复制,字符串,strlen,Size From: https://www.cnblogs.com/wangkaixin-yy/p/17680129.html