求字符串长度 总是说 ch 没有定义,我定义了结果错得更多了,该怎么办? 帮看看吧!
#include<iostream>#include<string>
using namespace std;
class strtype
{
public:
string ch;
int show();
};
int show()
{
int len=0;
while(ch!='\0')
{
len++;
}
cout<<"字符串的长度"<<len<<endl;
return 0;
}
int main()
{
strtype *p;
p=new strtype;
cout<<"Creating string"<<endl;
p->ch="we study new and delete";
cout<<"Deleting string"<<endl;
return 0;
}