首页 > 学院 > 开发设计 > 正文

5、流的输入与输出

2019-11-08 03:07:46
字体:
来源:转载
供稿:网友

C++定义的标准流主要包括 cin、cout、cerr、clog。

cin 是由终端输入数据,默认为键盘;

cout 为向终端输出数据,默认为屏幕;

cerr 是向终端输出标准错误信息,默认为屏幕;

clog 为 cerr 的缓冲形式,默认为屏幕。

用博客链接 中的例子,使用 cin() 和 cout() 计算两个日期之间的天数之差。

#include<iostream>#include<math.h>using namespace std;int f(int year,int month){	if (month<3)	{		return  year-1;	}	else	{	    return year;	}}int g(int month){	if (month<3)	{		return  month+3;	}	else	{	    return month+1;	}}int N_Value(int year,int month,int day){	int N = 1461*f(year,month)/4+153*g(month)/5+day;	return N;}void main(){   int year1,mongth1,day1,year2,mongth2,day2,N1,N2,dN;   cout<<"Please input integer year,mongth,day,the first date:"<<endl;   cin>>year1>>mongth1>>day1;   cout<<"Please input integer year,mongth,day,the seconddate:"<<endl;   cin>>year2>>mongth2>>day2;   N1 = N_Value(year1,mongth1,day1);   N2 = N_Value(year2,mongth2,day2);   dN = abs(N1-N2);   PRintf("There are %d days between the two dates./n",dN);}

结果:


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表