64,637
社区成员
发帖
与我相关
我的任务
分享
class mystring
{
public:
mystring(char *str = "mystring")
{
this->str = new char[strlen(str) + 1];
strcpy(this->str, str);
}
mystring(const mystring& other)
{
this->str = new char[strlen(other.str) + 1];
strcpy(str, other.str);
}
virtual ~mystring()
{
delete[] str;
}
friend ostream& operator<<(ostream& o, const mystring& ref)
{
o<<ref.str;
return o;
}
private:
char *str;
};
Vertor<mystring> vec_sting;
push_back(mystring("first"));
push_back(mystring("second"));
push_back(mystring("third"));
pop_back();
for(int n = 0; n != vec_sting.size() + 1; n++) //这里我特意size + 1来输出多一个。
{
cout << vec_sting[n] << '\t';
}