5、流的输入与输出

来源:互联网 发布:java的网络编程重要吗 编辑:程序博客网 时间:2024/06/04 18:28

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);}


结果:



0 0
原创粉丝点击