什么目的地<<源.rdbuf();在做什么?为什么太多的开盘关闭
what destination << source.rdbuf(); is doing ? why too many open close
if (!source.is_open() || !destination.is_open())
{
if (source.is_open())
{source.close();
}
if (destination.is_open())
{destination.close();
}
return -1;
}
destination << source.rdbuf();
source.close();
destination.close();
return 0;
destination
大概是输出字符流。<<
是一个二进制操作员,将右手操作数插入左手操作数的输出流中。在这种情况下,插入了source.rdbuf()
的结果。
source.rdbuf()
是一个函数调用。rdbuf
是source
的成员函数。source
大概在输入字符流中。在此假设下,rdbuf
的行为是根据文档的:
返回关联的流缓冲区。
将流缓冲区插入输出流的行为是根据文档的:
从[流缓冲区]控制的输入序列中提取字符,并将其插入[输出流],直到以下条件之一
- 文件结束发生在输入序列上;
- ...
作为一个例子,如果destination
是字符串流,而source
是文件流,则在操作后,字符串流的缓冲区内的字符串将包含文件的整个内容。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 什么时候在C++中返回常量引用是个好主意
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- C++避免重复声明的语法是什么
- c++库的公共头文件中应该包含什么
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- ifstream什么都没读
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- 什么是模板&lt;&gt;inline bla bla
- &lt;&lt;&lt;的这些超载有什么区别操作员
- 这是做什么的?如果(无符号(dx) & lt;无符号(大小))
- 什么会导致死亡<<变量& lt; & lt;“ t";当输出超过终端宽度时,打印空白而不是值