博客
关于我
c++的文件读写操作
阅读量:199 次
发布时间:2019-02-28

本文共 2010 字,大约阅读时间需要 6 分钟。

C++??????????????

??????????????????????C++???????????????????<fstream>????????????????????????C++?????????

1. ?????????

????????????????????????????????????????????????????????C++??<fstream>???????????????????ifstream????????ofstream????????

2. ??????????

?????????????????C++??????????????<fstream>??????????????

#include 
#include
using namespace std;

???????<iostream>?<fstream>??????<iostream>????????????<fstream>??????????

3. ?????????

?????????????????????????C++????????????ifstream?ofstream?????????????????????

int main() {    ifstream in("E:\\data_in.txt");    ofstream out("E:\\data_out.txt");        if (!in.is_open()) {        cout << "Open file failure1" << endl;    }    if (!out.is_open()) {        cout << "Open file failure2" << endl;    }        // ??????    // ...        in.close();    out.close();    return 0;}

?????????????????in??????out????????"E:\\data_in.txt"?"E:\\data_out.txt"???????????????????????

4. ?????????

??????????????????????C++?????????????>>??????????????????????

int u, v, w;while (!in.eof()) {    in >> u >> v >> w;    cout << u << " " << v << " " << w << endl;    out << u << "--" << v << " " << w << endl;}

???????????while?????????????????in >> u >> v >> w??????????????u?v?w???????????????????????cout????out?

5. ?????

?????????????????????????????????????????

in.close();out.close();

6. ??????

??????????????C++?????

#include 
#include
using namespace std;int main() { ifstream in("E:\\data_in.txt"); ofstream out("E:\\data_out.txt"); if (!in.is_open()) { cout << "Open file failure1" << endl; } if (!out.is_open()) { cout << "Open file failure2" << endl; } int u, v, w; while (!in.eof()) { in >> u >> v >> w; cout << u << " " << v << " " << w << endl; out << u << "--" << v << " " << w << endl; } in.close(); out.close(); return 0;}

7. ??

??????????????????C++???????????????????????????????????????????????????????????????????????

转载地址:http://jirn.baihongyu.com/

你可能感兴趣的文章
Python编程的终极十大工具
查看>>
python 堆排序
查看>>
python编程方式之一-函数式编程
查看>>
python 复习计划
查看>>
Python 多处理 apply_async 永远不会在 Windows 7 上返回结果
查看>>
Python 多处理 Numpy 随机
查看>>
Python 多处理 >= 125 列表永远不会完成
查看>>
Python 多处理:在第一个子错误时中止映射
查看>>
Python 多处理不断产生 pythonw.exe 进程而不做任何实际工作
查看>>
Python 多处理从不加入
查看>>
Python 多处理如何优雅地退出?
查看>>
Python 多处理将子进程的标准输出重定向到 Tkinter 文本
查看>>
Python 多处理库错误(AttributeError:__exit__)
查看>>
Python 多处理模块的 .join() 方法到底在做什么?
查看>>
python 多线程与GIL
查看>>
python 多进程-基础
查看>>
python 多进程-进阶-进程池
查看>>
python 多进程-进阶-进程间通信之Pipe
查看>>
python 多进程-进阶-进程间通信之Queue
查看>>
python 如何“否定“value : 如果为真则返回假,如果为假则返回真
查看>>