// 构造函数与析构函数.cpp : 定义控制台应用程序的入口点。
//要学习的两点:
//要想表现出析构函数,必须在对象外面加大括号!!
// while (cin.get() != ‘\n‘) num++;
#include "stdafx.h"
#include<iostream>
using namespace std;
class Count
{
public:
Count();
~Count();
void process();
private:
int num;
};
Count::Count()
{
num = 0;
}
Count::~Count()
{
cout << "The length of sentence:" << num << endl;
}
void Count::process()
{
while (cin.get() != ‘\n‘) //this is need to study!!
num++;
}
int main()
{
{
Count c;
c.process();
}//要想表现出析构函数,必须在对象外面加大括号!!
system("pause");
return 0;
}
时间: 2024-11-05 01:51:59