container<type> c; 输出语句为:copy(c.begin(), c.end(), ostream_iterator<type>(cout, " ")); 这句代码将依次向屏幕输出容器中的元素,元素之间用" "空格分开。 空格可以换成其他的C-Sty1e字符串。 需要使用<algor ...
分类:
其他好文 时间:
2018-09-11 21:13:07
阅读次数:
134
friend ostream& operator(ostream &out, Complex &c);template ostream& operator &c){ out << c.a << " " << c.b << endl; return out;} ...
分类:
其他好文 时间:
2018-09-04 17:50:46
阅读次数:
162
C++中流(stream)是一个对象,所以任何有流这种行为的对象也是流对象。 流主要分为三种类型: istream: 主要是从流中执行输入操作 ostream:主要是从流中执行输出操作 iostream:主要是从流中执行输入输出操作 每个流对象都关联一个流buffer,程序一般从buffer中读取数 ...
分类:
编程语言 时间:
2018-08-28 20:17:07
阅读次数:
201
iostream库包含两个基础类型 istream 和 ostream ,分别表示输入流和输出流。 标准库定义了4个IO对象: std::cin标准输入 std::cout标准输出 std::cerr标准错误,用来输出警告和错误信息 std::clog用来输出程序运行时的一般性信息 加法: 1 #i ...
分类:
其他好文 时间:
2018-08-22 14:05:11
阅读次数:
297
1.output函数 #include<iostream.h> ostream& operator<< (ostream& os, const String& str){ os << str.get_c_str(); return os; } { String s1("hello"); cout < ...
分类:
编程语言 时间:
2018-08-20 21:49:54
阅读次数:
185
C++文件操作归纳总结: C++ 通过以下几个类支持文件的输入输出:ofstream: 写操作(输出)的文件类 (由ostream引申而来) ifstream: 读操作(输入)的文件类(由istream引申而来) fstream: 可同时读写操作的文件类 (由iostream引申而来) 打开文件(O ...
分类:
编程语言 时间:
2018-08-20 16:34:32
阅读次数:
203
上面的程序如果没有#include<string>,则cin>>str1将会报错,而string str1不会报错,那么std::string是在哪里定义的? 头文件之间的包含关系如下 #include <iostream> #include <istream> #include <ostream> ...
分类:
其他好文 时间:
2018-07-28 22:45:18
阅读次数:
198
参考《C++ Primer Plus》P788 iostream族支持 程序 与 终端 之间的I/O fstream族支持 程序 与 文件 之间的I/O sstream族支持 程序 与 string对象 之间的I/O,也就是说,可以使用cout的ostream方法将格式化信息写入string对象中, ...
分类:
编程语言 时间:
2018-07-03 21:36:12
阅读次数:
230
1 //可流类 2 //把复数类设计成可流复数类 3 #include 4 5 template 6 class Complex{ 7 friend ostream & operator &com); 8 friend istream & operator>>(istream &is,Complex... ...
分类:
编程语言 时间:
2018-07-02 00:15:09
阅读次数:
198
1 //ostream类 2 //put成员函数的功能是把一个字符插入到输入流中 3 //write成员函数是从字符串数组中提取若干个字符插入到输出流中 4 #include 5 int main(){ 6 7 char ch1[]="i="; 8 char ch2[]="x="; 9 10 int... ...
分类:
编程语言 时间:
2018-07-01 19:04:42
阅读次数:
141