C++ ofstream/ifstream读写文件demo
2018-01-27 17:05
671 查看
#include <iostream> #include <fstream> using namespace std; int main(){ //1.ofstream写入out.txt const char * filename = "test.txt"; string end= "123456"; ofstream out("out.txt"); if(out.is_open()) { /* "<<":插入器,向流输出数据. ">>":析取器,向流输出数据. */ out<<"Hello World." << filename << " "<< end << endl; out.close(); } //2.读取out.txt ifstream in("out.txt"); char buffer[200]; if(in.is_open()) { while(!in.eof()) { in.getline(buffer, 100); cout << buffer << endl; out.close(); } } }
相关文章推荐
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- 【c/c++】C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)