【足迹C++primer】21、IO类

IO类

IO库类型和头文件




注意宽字符版本的都是在前面加个w,比如:wistream,wostream,wiostream,wifstream。。。


IO对象无拷贝或赋值

ofstream out1, out2;
out1=out2;      //错误:不能对流对象赋值
ofstream print(ofstream);   //错误不能初始化ofstream参数
out2=print(out2);       //错误:不能拷贝流对象

刷新输出缓冲区

cout<<"hi!"<<endl;      //输出hi和一个换行,然后刷新缓冲区
cout<<"hi!"<<flush;     //输出hi,然后刷新缓冲区,不附加任何额外字符
cout<<"hi!"<<ends;      //输出hi和一个空字符,然后刷新缓冲区

unitbuf操纵符

cout<<unitbuf;      //所以输出操作后都会立即刷新缓冲区
//任何输出都立即刷新,无缓冲
cout<<nounitbuf;        //回到正常的缓冲方式


关联输入和输出流

cin.tie(&cout);     //将cin和cout关联起来
//old_tie指向当前关联到cin的流
ostream *old_tie=cin.tie(nullptr);  //cin不在与其他流关联
//将cin与cerr关联;这不是一个好主意,因为cin应该关联到cout
cin.tie(&cerr);     //读取cin会刷新cerr而不是cout
cin.tie(old_tie);   //从建cin和cout间的正常关联

PS:这章流的开头,说实话我不太清楚,你说看懂了没?看懂了,理解了没,没理解透,会用吗?完全不会!!!!大笑不过等我慢慢摸索,相信我一定可以搞定他们的!!得意




























  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一小部分代码 请参考 org 0000h jmp start ;Start of the program org 0100h start: mov A,#030h ;1 line, 8 bits call wrcmd mov A,#LCD_SETVISIBLE + 4 call wrcmd mov A,#LCD_SETDDADDR+15 ; Start at right hand side of the display call wrcmd mov A,#LCD_SETMODE + 3 ; Automatic Increment - Display shift left. call wrcmd mov 025h,#00h ; Set output mode (floating point). call boundsbuffer ; Initialise the bounds buffer - used for error checking. mov mode,#4 ; Initialise the constant buffer to 100. Primarily used for % ops. mov digitcode,#031h call storedigit mov digitcode,#030h call storedigit mov digitcode,#030h call storedigit mov status,#00h ; variable used to determine the first key press after an operation. mov bufferctr,#00h mov opcounter,#00h mov decimalcnt,#00h call waitkey halt: mov PCON,#1 ;Halt ;*********************************************************** ;**** Floating Point Package **** ;******************************** $INCLUDE (FP52.ASM) ;Routine to peek arg at DPTR argout: mov R0,#FP_NUMBER_SIZE aoloop: movx A,@DPTR anl A,#0F0h rr a rr a rr a rr a add A,#aodata-$-3 movc A,@A+PC call sndchr movx A,@DPTR anl A,#0Fh add A,#aodata-$-3 movc A,@A+PC call sndchr inc DPTR djnz R0, aoloop ret aodata: db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' ;Routine to output character in A, preserving all but A. sndchr: push R0B0 push R1B0 call getmode mov digitcode,A call storedigit pop R1B0 pop R0B0 ret ;Routine to print error message at DPTR. prterr: jmp wrstr ;Routine to handle input parameter error. badprm: mov DPTR,#bpmsg jmp wrstr bpmsg: db 'Bad Parameter',0 ;*********************************************************** ;**** LCD Display Routines **** ;****************************** ;LCD Registers addresses LCD_CMD_WR equ 00h LCD_DATA_WR equ 01h LCD_BUSY_RD equ 02h LCD_DATA_RD equ 03h LCD_PAGE equ 80h ;LCD Commands LCD_CLS equ 1 LCD_HOME equ 2 LCD_SETMODE equ 4 LCD_SETVISIBLE equ 8 LCD_SHIFT equ 16 LCD_SETFUNCTION equ 32 LCD_SETCGADDR equ 64 LCD_SETDDADDR equ 128
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值