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

一、继承:基类-派生类

(C++)标准IO库:面向对象的标准库_第1张图片

二、3个头文件

三、9个标准库类型

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

#include 
#include 
#include 
#include 

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++)