//COUNT类中的函数先于主程序执行//
#include<iostream.h>
#include<stdio.h>
class COUNT
{
int num;
public:
COUNT();
~COUNT();
void process();
};
void COUNT::process()
{
while(getchar()!='\n') num++;
cout<<endl;
}
COUNT::~COUNT()
{
cout<<"字符个数:"<<num<<endl;
}
COUNT::COUNT()
{
num=0;
}
void main()
{
COUNT c;
cout<<"请输入一行字符串:";
c.process();
}
#include<iostream.h>
#include<stdio.h>
class COUNT
{
int num;
public:
COUNT();
~COUNT();
void process();
};
void COUNT::process()
{
while(getchar()!='\n') num++;
cout<<endl;
}
COUNT::~COUNT()
{
cout<<"字符个数:"<<num<<endl;
}
COUNT::COUNT()
{
num=0;
}
void main()
{
COUNT c;
cout<<"请输入一行字符串:";
c.process();
}