读书人

c++ string类的测试有关问题

发布时间: 2012-06-03 16:59:40 作者: rapoo

c++ 求助string类的测试问题
bool operator==(const String &a, const String &b){
return !strcmp(a.str, b.str);
}

bool operator>(const String &a, const String &b){
return strcmp(a.str, b.str) > 0;
}
bool operator>=(const String &a, const String &b){
return strcmp(a.str, b.str) >= 0;
}
还有
char & String::operator[](int n){
return str[n];
}

main函数怎么写来测试对错?

[解决办法]
就直接写不就好了么 string str1,str2;
if(str1==str2)...
if(str1>str2)...
for ( int n=0 ; n<str.getlength() ; n++ )
printf("%c",str1[n]) ;

读书人网 >C++

热点推荐