流类库与输入输出流(C++)
1.输出流类
①ostream:
cout:标准输出流
cerr:标准错误输出流,没有缓冲
clog:和cerr类似,但有缓冲
cout、cerr、clog是ostream类的对象,直接使用
②ofstream:支持磁盘文件操作
使用ofstream将信息输入到文件时,需要构造对象
(1)默认构造函数构造对象:
ofstream file;
file.open("filename");
(2)构造对象同时指定文件名
ofstream file("filename");
③ostringstream:用于生成字符串
具有一个形参的构造函数:
ostringstream os(ios_base::out);
形参用于指定打开方