【1】类型的概念
定义了数据元素的内容,还定义了这类数据上可以操作的运算。
【2】endl的作用
endl是操作符的特殊值。写入endl的效果是结束当前行,并将于设备关联的缓冲区的中内容刷到设备中。缓冲刷新操作可以保证目前为止程序所产生的的所有输出都真正写入输出流中,而不是仅停留在内存中等待写入流。
【3】练习1.11(while循环的使用)
#include<iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
while (a+1< b)
{
cout << ++a << endl;
}
return 0;
}
【4】读取数量不定的输入数据
while(cin>>value)
【5】使用if语句统计输入的数据中相同数字的个数
#include<iostream>
using namespace std;
int main()
{
int cVal, val = 0;
if (cin >> cVal)
{
int cnt = 1;
while (cin >> val)
{
if (val == cVal)
++cnt;
else
{
cout << cVal << "occurs" << cnt << "times!" << endl;
cVal = val;
cnt = 1;
}
}
cout << cVal << "occurs" << cnt << "times!" << endl;
}
return 0;
}