ca72a_c++_标准IO库:面向对象的标准库
2024-09-07 16:38:59
/*ca72a_c++_标准IO库:面向对象的标准库
继承:基类-》派生类
3个头文件
9个标准库类型
IO对象不可复制或赋值
ofstream, f--file,文件输出流
ostringstream,o--输出,string字符串输出流
iostream--输入输出流
istringstream,i-输入,string字符串输入流
ifstream,i--输入,f--file,文件输入流
stringstream--字符串输入输出流, <sstream> ////字符串输入输出流头文件
fstream--文件输入输出流
*/
/*ca72a_c++_标准IO库:面向对象的标准库
继承:基类-》派生类
3个头文件
9个标准库类型
IO对象不可复制或赋值 ofstream, f--file,文件输出流
ostringstream,o--输出,string字符串输出流
iostream--输入输出流 istringstream,i-输入,string字符串输入流
ifstream,i--输入,f--file,文件输入流 stringstream--字符串输入输出流, <sstream> ////字符串输入输出流头文件
fstream--文件输入输出流 */ #include <iostream>
#include <fstream>
#include <sstream> ////字符串输入输出流头文件 using namespace std;
//void print(std::ofstream of)
//{
// cout << "test!" << endl;
//}
void print(std::ofstream &of)//传递引用
{
cout << "ofstream test" << endl;
}
ofstream& print1(std::ofstream &of)//传递引用
{
cout << "ofstream test" << endl;
std::ofstream of2;
return of2;//返回引用是可以的, ofstream&
} void foo(ostream& os)
{
cout << "test ostream" << endl;
//os << "test ostream" << endl;
} int main()
{
//cout是ostream输出流对象
//cout都是在std名称空间里面。std::cout,std::endl;,std::cin
cout << "hello world!" << endl;
fstream fs;//文件输入输出流
//或者。std::fstream std::stringstream ss;//字符串输入输出流 std::ofstream out1, out2;
//out1=out2;//错误。IO对象不可复制或赋值
//print(out1);//错误。IO对象不可复制或赋值,可以传参数与引用
print(out1);//可以传参数与引用 //vector<ofstream> vec;//不能用容器 foo(cout);//传递cout,cout是ostream cout << "ofstream test!!!" << endl;
std::ofstream ofs;
foo(ofs);// foo(ostream& os) osstream是基类,所以也可以接受它的派生类,ofstream ostringstream oss;
foo(oss);// foo(ostream& os) osstream是基类,所以也可以接受它的派生类,ostringstream
return ;
}
最新文章
- Mybatis XML配置
- Masonry介绍与使用实践:快速上手Autolayout
- sqlserver 2005 数据误删恢复
- String空值判定
- TEX学习笔记
- Winform以任意角度旋转PictureBox中的图片的方法
- 基于网格的波动方程模拟(Wave equation on mesh)附源码
- CodeForce---Educational Codeforces Round 3 D. Gadgets for dollars and pounds 正题
- 提交表单时的等待(loading)效果
- maven 编
- Multidimensional Arrays
- Apriori算法-java
- LeetCode之“数学”:Plus One
- iview源码解析(1)
- 05 - json转成树状结构
- hive资料
- 2.3 UML活动图
- QWebEngine_C++_交互
- LinUX系统ThinkPHP5链接MsSQL数据库的pdo_dblib扩展
- 20155207 实验四 《Android程序设计》实验报告