要实现格式化输入输出,程序需要包含 iostreams 标准标头 <iomanip> 以定义几个各自采用单个参数的操控器。 备注: 其中每个操控器都返回重载 basic_istream<Elem, Tr>::operator>> 和 basic_ostream<Elem, Tr>::operator ...
分类:
编程语言 时间:
2017-06-30 19:58:06
阅读次数:
241
1、cin>>s; s能够是:string s、char s[]; 这个是ostream中的函数。遇到‘ ’(空格) , '\n'(换行),就会自己主动结束,因此假设用cin读取字符串,那么这个字符串中不能含有空格和换行。 cin由于不识别空格和换行,因此假设在输入字符串的时候,在字符開始处输入了空 ...
分类:
编程语言 时间:
2017-06-27 20:48:23
阅读次数:
214
(1)标准输入流cin:istream类的对象。(2)标准输出流cout:ostream类的对象。 (3)非缓冲型标准出错流cerr:ostream类的对象。(4)缓冲型标准出错流clog:ostream类的对象 extern用于声明外部变量的。register声明寄存器类型变量 多态性有两种静态多 ...
分类:
编程语言 时间:
2017-06-21 13:46:04
阅读次数:
172
先看一段会造成死机的代码及其运行结果:#include<iostream>
usingstd::cout;
usingstd::endl;
usingstd::ostream;
classTree{
intheight;
public:
Tree(inttreeHeight):height(treeHeight){
cout<<__func__<<"(),this="<<this<<endl;
}
~Tree(..
分类:
其他好文 时间:
2017-06-15 16:29:50
阅读次数:
151
对指针调用delete之后要记得把指针赋值为nullptr否则,如果这个指针被重复delete,会死机。#include<iostream>
usingstd::cout;
usingstd::endl;
usingstd::ostream;
classTree{
intheight;
public:
Tree(inttreeHeight):height(treeHeight){
cout<<__func__<&..
分类:
其他好文 时间:
2017-06-15 16:28:37
阅读次数:
313
如题,否则会在调用"std::cout<<this"时”偷偷“调用这个友元函数。本来是想看这个对象的指针值,却看到”不想看到的事情”。#include<iostream>
usingstd::cout;
usingstd::endl;
usingstd::ostream;
classTree{
intheight;
public:
Tree(inttreeHeight):height(..
分类:
其他好文 时间:
2017-06-15 16:20:57
阅读次数:
157
std::cout是在#include<iostream>库中的ostream类型中的对象 ...
分类:
编程语言 时间:
2017-06-11 10:24:34
阅读次数:
268
关于输入(cin)/输出(cout)的重载。在C++的头文件中有#include<iostream>,实际上就包含着cin/cout,具体上:ostream中对应的是cout,而istream对应的是cin。我先实现cout重载#include<iostream>
usingnamespacestd;
classOc
{
public:
private:
intcnt;
public..
分类:
编程语言 时间:
2017-05-21 21:42:02
阅读次数:
193
流迭代器 2017-05-21 17:05:51 流迭代器是标准模板库STL中的,是类模板,流迭代器实例化之后即可以和任何接受对应迭代器的函数一起使用(可以将流看做一个容器,把数据存储在一个连续的缓冲区中,具有迭代器的功能和类似使用)。 istream_iterator 和ostream_itera ...
分类:
编程语言 时间:
2017-05-21 17:53:30
阅读次数:
254
第八章:IO库不直接来处理输入输出,而是通过在标准库中的一些类型来处理io istream ostream cin cout cerr getline函数 iostream:定义了用于基本读写流的基本类型 fstream: 定义了基本的读写命名文件的类型 sstream:定义了读写内存的string... ...
分类:
编程语言 时间:
2017-05-16 17:32:02
阅读次数:
314