python做网站 框架,建设公司网站的可行性研究,企业邮箱注册申请免费注册126,分析网站的优势和不足目录 一、C的标准输出流
#xff08;一#xff09;cout、cerr和clog流对象
1、cout 流对象
2、cerr 流对象
3、clog流对象
#xff08;二#xff09;用函数put输出字符
#xff08;三#xff09;用函数 write 输出字符 一、C的标准输出流
标准输出流——流向标准输…目录 一、C的标准输出流
一cout、cerr和clog流对象
1、cout 流对象
2、cerr 流对象
3、clog流对象
二用函数put输出字符
三用函数 write 输出字符 一、C的标准输出流
标准输出流——流向标准输出设备(显示器)的数据。
ostream类定义了3个输出流对象,即cout、cerr 和 clog。
一cout、cerr和clog流对象
1、cout 流对象
cout 必须和运算符“”一起使用。用cout 进行输出的一般形式为: cout输出项1输出项2…; 它的功能是将输出项1、输出项2…插入到输出流cout中,然后由C系统将cout中的内容输出到显示器上。
#includeiostream
using namespace std;
int main()
{cout 1 a abcd 1.2 endl;return 0;
} 在C的头文件 iostream.h中,定义了一个代表回车换行的控制符“endl”,其作用与“\n”相同。如下列3条输出语句是等价的:
#includeiostream
using namespace std;
int main()
{cout C Program\n;cout C Proqram \n;cout C Program endl;return 0;
}
cout流在内存中对应开辟了一个缓冲区,用来存放流中的数据,当向cout流插入一个“endl”时,不论缓冲区是否已满,都立即输出流中的所有数据,然后插入一个换行符,并刷新流(清空缓冲区)。
需要注意的是: ① 系统已经对“”运算符作了重载函数,因此用“cout”输出基本类型的数据时,可以不必考虑数据是什么类型。 ② 在 iostream.h头文件中只对“”和“”运算符用于标准类型数据的输入输出进行了重载,但未对用户自定义类型数据的输入输出进行重载。 ③ 在用cout进行输出时,每输出一项都要用一个“”运算符。例如:输出语句: couta a , bbendl; 不能写成: couta,a,,,b,bendl; 2、cerr 流对象 cerr流对象是标准出错流,它的作用是向输出设备输出出错信息。
cerr与标准输出流cout的作用和用法类似。
但不同的是 cout流通常是传送到显示器输出、但也可以被重定向输出到磁盘文件; cerr 流中的信息只能在显示器输出. 当调试程序时,如果不希望程序运行时的出错信息被送到其他文件,这时应该用cerr。
检测输人的一个数是否是正数,如果是,就输出;如果不是,输出错误信息.
#includeiostream
using namespace std;int main() {float a; cout please enter the value of a:; cin a; if (a 0)//将有关出错信息插人cerr流,在屏幕输出cerr a is equal to zero, error! endl; else if (a 0)cerr a is not a proper data. error! endl;elsecout a a endl;return 0;
}
输入1 please enter the value of a:1 a1 输入0 please enter the value of a:0 0 is equal to zero, error! 输入-1 please enter the value of a:-1 -1 is not a proper data. error! 3、clog流对象
clog流对象也是标准出错流,其作用和cerr相同,都是终端显示器上显示出错信息。只不过cerr是不经过缓冲区,直接向显示器上输出有关信息而clog中的信息存放在缓冲区中缓冲区满后或遇endl时才向显示器输出。
二用函数put输出字符
ostream类的成员函数put提供了一种将单个字符送进输出流的方法,其使用方法如下:
#includeiostream
using namespace std;
int main()
{char a m;cout.put(a);//会输出显示字符mcout.put(m);//会输出和上一句相同的结果return 0;
} 另外,调用put函数的实参还可以是字符的ASCII码或者一个整型表达式,如
cout.put(65 32);//显示字符a,因为97是字符a的ASCII号
可以在一个语句中连续调用put函数,如:
cout.put(71).put(79).put(79).put(68).put(\n);//在屏幕上显示G00D
还可以用putchar函数输出一个字符。putchar函数是C语言中使用的,在stdio.h头文件中定义。C保留了这个函数,在iostream.h头文件中定义。
三用函数 write 输出字符
ostream类的成员函数write是一种将字符串送到输出流的方法,该函数在iostream类体中的原型声明语句如下:
ostream write(const char* pch, int nCount);
ostream write(const unsigned char* puch, int nCount);
ostream write(const signed char* psch,int nCount);
其中,第1个参数是待输出的字符串,第2个参数是输出字符串的字符个数。
如输出器串常量“C program”,可以这样实现:
cout.write(Cprogram,strlen(Cprogram));
#includeiostream
#includestring
using namespace std;
void writestring(char* str)
{cout.write(str, strlen(str)).put(\n);cout.write(str, 6) \n;
}
int main()
{char es[]Cprogram;cout yhe string is: es endl;writestring(es); return 0;
} 运行程序结果 yhe string is: Cprogram Cprogram Cpro 该程序中使用write 函数显示字符,不但可以显示整个字符串的内容,也可以显示部分字符串的内容。 文章转载自: http://www.morning.bpncd.cn.gov.cn.bpncd.cn http://www.morning.hxlpm.cn.gov.cn.hxlpm.cn http://www.morning.gtjkh.cn.gov.cn.gtjkh.cn http://www.morning.shxrn.cn.gov.cn.shxrn.cn http://www.morning.tbwsl.cn.gov.cn.tbwsl.cn http://www.morning.sqgqh.cn.gov.cn.sqgqh.cn http://www.morning.psgbk.cn.gov.cn.psgbk.cn http://www.morning.rrcrs.cn.gov.cn.rrcrs.cn http://www.morning.kynf.cn.gov.cn.kynf.cn http://www.morning.rjnm.cn.gov.cn.rjnm.cn http://www.morning.xkzr.cn.gov.cn.xkzr.cn http://www.morning.ffksr.cn.gov.cn.ffksr.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.zpzys.cn.gov.cn.zpzys.cn http://www.morning.flqkp.cn.gov.cn.flqkp.cn http://www.morning.yzygj.cn.gov.cn.yzygj.cn http://www.morning.hqxyt.cn.gov.cn.hqxyt.cn http://www.morning.tdldh.cn.gov.cn.tdldh.cn http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn http://www.morning.jpqmq.cn.gov.cn.jpqmq.cn http://www.morning.bydpr.cn.gov.cn.bydpr.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.yhrfg.cn.gov.cn.yhrfg.cn http://www.morning.cbpkr.cn.gov.cn.cbpkr.cn http://www.morning.llllcc.com.gov.cn.llllcc.com http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn http://www.morning.rmxk.cn.gov.cn.rmxk.cn http://www.morning.clkjn.cn.gov.cn.clkjn.cn http://www.morning.lfqnk.cn.gov.cn.lfqnk.cn http://www.morning.nwwzc.cn.gov.cn.nwwzc.cn http://www.morning.xnkh.cn.gov.cn.xnkh.cn http://www.morning.jqmqf.cn.gov.cn.jqmqf.cn http://www.morning.rqgq.cn.gov.cn.rqgq.cn http://www.morning.qflcb.cn.gov.cn.qflcb.cn http://www.morning.lcdtb.cn.gov.cn.lcdtb.cn http://www.morning.xcjbk.cn.gov.cn.xcjbk.cn http://www.morning.nlgyq.cn.gov.cn.nlgyq.cn http://www.morning.mnkz.cn.gov.cn.mnkz.cn http://www.morning.jfjfk.cn.gov.cn.jfjfk.cn http://www.morning.pljxz.cn.gov.cn.pljxz.cn http://www.morning.ygpdm.cn.gov.cn.ygpdm.cn http://www.morning.cwyfs.cn.gov.cn.cwyfs.cn http://www.morning.ktblf.cn.gov.cn.ktblf.cn http://www.morning.cwgt.cn.gov.cn.cwgt.cn http://www.morning.gtcym.cn.gov.cn.gtcym.cn http://www.morning.xhklb.cn.gov.cn.xhklb.cn http://www.morning.ffydh.cn.gov.cn.ffydh.cn http://www.morning.zdxinxi.com.gov.cn.zdxinxi.com http://www.morning.c7501.cn.gov.cn.c7501.cn http://www.morning.pbgnx.cn.gov.cn.pbgnx.cn http://www.morning.phnbd.cn.gov.cn.phnbd.cn http://www.morning.pcqdf.cn.gov.cn.pcqdf.cn http://www.morning.mxdiy.com.gov.cn.mxdiy.com http://www.morning.tbhf.cn.gov.cn.tbhf.cn http://www.morning.mkczm.cn.gov.cn.mkczm.cn http://www.morning.lbrrn.cn.gov.cn.lbrrn.cn http://www.morning.gsjfn.cn.gov.cn.gsjfn.cn http://www.morning.wqpm.cn.gov.cn.wqpm.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.wlqll.cn.gov.cn.wlqll.cn http://www.morning.wmcng.cn.gov.cn.wmcng.cn http://www.morning.zdhnm.cn.gov.cn.zdhnm.cn http://www.morning.tkrpt.cn.gov.cn.tkrpt.cn http://www.morning.gfprf.cn.gov.cn.gfprf.cn http://www.morning.nrchx.cn.gov.cn.nrchx.cn http://www.morning.divocn.com.gov.cn.divocn.com http://www.morning.qsbcg.cn.gov.cn.qsbcg.cn http://www.morning.frmmp.cn.gov.cn.frmmp.cn http://www.morning.spkw.cn.gov.cn.spkw.cn http://www.morning.prkdl.cn.gov.cn.prkdl.cn http://www.morning.hfytgp.cn.gov.cn.hfytgp.cn http://www.morning.ngcth.cn.gov.cn.ngcth.cn http://www.morning.tbnpn.cn.gov.cn.tbnpn.cn http://www.morning.zsfooo.com.gov.cn.zsfooo.com http://www.morning.snbq.cn.gov.cn.snbq.cn http://www.morning.swimstaracademy.cn.gov.cn.swimstaracademy.cn http://www.morning.sbrjj.cn.gov.cn.sbrjj.cn http://www.morning.bbmx.cn.gov.cn.bbmx.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.mjwnc.cn.gov.cn.mjwnc.cn