欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

(C++)标准IO库:面向对象的标准库

程序员文章站 2022-06-07 14:14:50
...

一、继承:基类-派生类

(C++)标准IO库:面向对象的标准库

二、3个头文件

三、9个标准库类型

四、IO对象不可复制或者赋值

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>

using namespace std;

void print1(ofstream of)
{
	cout << "test" << endl;
}

void print2(ofstream &of)  //传递引用是可以的
{
	cout << "test" << endl;
}

void foo(ostream& os)
{
	cout << "test ostream" << endl;
}

int main()
{
	//cout是ostream输出流对象
	cout << "Hello C++!" << endl;

	fstream fs;
	stringstream ss;

	ofstream out1, out2;
	//out1 = out2; //是错误的 IO对象不可赋值或者复制

	//print1(out1);//错误,调用print函数需要把out1复制到 ofstream中,而 IO对象不可复制
	print2(out2);//传递引用是可以的


	vector<ofstream> vec;
	vec.push_back(out1);
	vec.push_back(out2);


	foo(cout);

	ofstream ofs;//ofstream是ostream的派生类,派生类都可以传递到基类当中
	foo(ofs);

    return 0;
}
相关标签: C++ c++