//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();
}
本文介绍了一个简单的C++程序,通过定义一个名为COUNT的类来统计输入字符串中的字符数量。该类包括构造函数、析构函数及成员函数process(),用于处理输入并更新字符计数。
1709

被折叠的 条评论
为什么被折叠?



