c++输入输出/文件流
来源:互联网 发布:java短信开发网关 编辑:程序博客网 时间:2024/06/05 05:28
常用流
cin:
cin.get(1/2/3个参数)
cin.get(myInt1).get(myInt2).get(myInt3);
cin.getline()
cin.getline(a,256)
cin.ignore() //去掉一个字符
cin.peek() //只看不读
cin.putback() //放回去一个字符
cout:
cout<<hex<<123<<endl; //16进制显示
cout.flush()
cout.put()
cout.write()
cout.width() //设置占据空间
cout.fill() //填充
cout.fill(‘*’)
cout.setf()
cerr
clog
读写二进制文件
#include<iostream>#include<fstream>using namespace std;class Animal{private:int itsWeight;long DaysAlive;public:Animal(int weight, long days) :itsWeight(weight), DaysAlive(days) {}~Animal(){}int GetWeight() const { return itsWeight; }void SetWeight(int weight) { itsWeight = weight; }long GetDaysAlive() const { return DaysAlive; }void SetDaysAlive(long days) { DaysAlive = days; }};int main(){char fn[255] = "d:\\a.mal"; //可自己定义拓展名ofstream fout(fn,ios::binary); //打开一个文件if (!fout){cout << "unable to open" << fn << "for writing.\n";return(1);}Animal bear(50, 100);fout.write((char *)&bear, sizeof bear);fout.close();ifstream fin(fn, ios::binary);if (!fin){cout << "unable to open" << fn << "for writing.\n";return(1);}Animal BearTwo(1, 1);fin.read((char *)&BearTwo, sizeof Animal);cout << BearTwo.GetWeight() << endl;cout << BearTwo.GetDaysAlive() << endl;cin.get();return 0;}
0 0
- C文件输入输出流
- C#OOP 之九 文件输入输出流
- C#-文件输入输出
- C/C++ 文件输入输出
- C++_文件输入输出
- c 文件输入输出
- 【c++】文件的输入输出
- 文件输入输出(C++)
- C 文件输入输出
- C语言文件输入输出
- C输入输出与文件
- C/C++文件输入输出
- c语言文件输入输出
- c语言文件输入输出
- C/C++标准输入输出与文件输入输出
- C/C++标准输入输出与文件输入输出
- C/C++标准输入输出与文件输入输出
- C/C++,Java 重定向输入输出流至文件
- 跟龙哥学java web ,关于filter学习
- 给指定日期得到 星期几
- IntelliJ Idea+GitHub设置同步工程
- linux grep命令
- git免密码pull,push
- c++输入输出/文件流
- 调试APP LOGCAT提示 Debugger is no longer active
- 26-javascript面向对象基础-01
- 格式化数字为小数点两位(四舍五入)
- SVN教程
- Intellij IDEA连接Git@OSC
- Oracle数据字典概述
- Android 更新UI——runOnUiThread()
- tinyhttp web服务器设计及完整代码