xstr& xstr:perator = (const xstr & rhs) {
if (len < rhs.len) {
delete [] _str;
_str = new char[rhs.len+1];
}
strncpy(_str, rhs._str, MAXCHAR);
return *this;
}
istream& operator >> (istream &inputStream, xstr & str_a) {
char ch;
if (str_a.len < MAXCHAR) {
if (str_a._str != NULL)
delete [] str_a._str;
str_a._str = new char[MAXCHAR+1];
}
int ct =0;
inputStream >> ch;
while ((isalnum(ch))&&(ct<MAXCHAR)) {
str_a._str[ct++] = ch;
inputStream >> ch;
}
str_a._str[ct]='\0';
return inputStream;
}
原帖由 tyc611 于 2006-10-4 10:34 发表
没有修改len成员的值
原帖由 namtso 于 2006-10-4 03:33 发表
xstr:str(const char *stra) {
len = strlen(stra);
_str = new char[len+1];
strncpy(_str, stra, MAXCHAR);
}
这里溢出了。。。。。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |