【例11.5】用输出成员函数在屏幕上输出 串字符“Helo!”。 #include <iostream.h> void main(void) cout. put(H) cout. put(e); cout. put(1); cout.put(r) cout. put(o; cout.put(!); cout put('in) 人民邮电出版 POSTS tEl 动此映
【例11.5】用输出成员函数在屏幕上输出 一串字符“Hello!” 。 #include <iostream.h> void main(void) { cout.put('H'); cout.put('e'); cout.put('l'); cout.put('l'); cout.put('o'); cout.put('!'); cout.put('\n'); }
实际上,下面两条语句是等价的: cout<< a cout put(a); 两者都在屏幕上输出一个字符a。 人民邮电出版社 POSTS tEl OM PRE 动此映
实际上,下面两条语句是等价的: cout<<'a'; cout.put('a'); 两者都在屏幕上输出一个字符a
2. write()函数 成员函数 write()输出一串字符。该成员 函数一般形式是: write(char* pch, int n Count) 其中,pch是指向字符数组的指针 n Count指明从第一个参数中复制输出字符 的个数。 人民邮电出版社 POSTS tEl OM PRE 动此映
2. write()函数 成员函数write()输出一串字符。该成员 函数一般形式是: write(char* pch, int nCount) 其 中 , pch 是 指 向 字 符 数 组 的 指 针 , nCount指明从第一个参数中复制输出字符 的个数
例116】 write()函数应用举例。 #include <iostream.h> void main(void) char strl=You will be the C++ master !"i cout. write(str, sizeof(str)-1) cout<<end: cout. write(&str 4, 4)<<end; 人民邮电出版社 POSTS tEl OM PRE 动此映
【例11.6】write()函数应用举例。 #include <iostream.h> void main(void) { char str[]="You will be the C++ master !"; cout.write(str,sizeof(str)-1); cout<<endl; cout.write(&str[4],4) <<endl; }
运行程序,输出结果为: You will be the ct+ master 人民邮电出版社 POSTS tEl OM PRE 动此映
运行程序,输出结果为: You will be the C++ master ! will