博客
关于我
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/

你可能感兴趣的文章
ollama-python-Python快速部署Llama 3等大型语言模型最简单方法
查看>>
ollama本地部署DeepSeek(Window图文说明)
查看>>
ollama运行多模态模型如何进行api测试?
查看>>
Omi 多端开发之 - omip 适配 h5 原理揭秘
查看>>
On Error GOTO的好处
查看>>
onclick事件的基本操作
查看>>
oncopy和onpaste
查看>>
onCreate中的savedInstanceState作用
查看>>
onCreate()方法中的参数Bundle savedInstanceState 的意义用法
查看>>
One good websit for c#
查看>>
OneASP 安全公开课,深圳站, Come Here, Feel Safe!
查看>>
OneBlog Shiro 反序列化漏洞复现
查看>>
one_day_one--mkdir
查看>>
ONI文件生成与读取
查看>>
Online PDF to PNG、JPEG、WEBP、 TXT - toolfk
查看>>
onlyoffice新版5.1.2版解决中文汉字输入重复等问题
查看>>
onnx导出动态输入
查看>>
onnx导出动态输入
查看>>
onScrollStateChanged无效
查看>>
onTouchEvent构造器
查看>>