读写文件(fstream)
2013-07-24 14:47
162 查看
// rw.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include <fstream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int nYear,nMonth,nDate; ifstream fin("C:\\Users\\sony\\Desktop\\1.txt"); if(!fin.bad()) { fin.ignore(256,'\n'); fin>>nYear>>nMonth>>nDate; cout<<"文件中的日期是:"<<nYear<<"-"<<nMonth<<"-"<<nDate<<endl; fin.close(); } else { cout<<"无法打开文件并进行读取"<<endl; } cout<<"请输入当前的日期:"<<endl; cin>>nYear>>nMonth>>nDate; ofstream fout("C:\\Users\\sony\\Desktop\\1.txt"); if(!fout.bad()) { fout<<"用户输入的当前日期是:\n"<<nYear<<" "<<nMonth<<" "<<nDate; fout.close(); } else { cout<<"无法打开文件并进行写入"<<endl; } return 0; }这里是将写入的东西覆盖了以前的文字,所希望的是在以前的基础上加上现在输入的文字。
相关文章推荐
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- c++中使用fstream读写文件
- C++文件读写详解(ofstream,ifstream,fstream)
- 文件操作ofstream,open,close,ifstream,fin,按照行来读取数据, fstream,iosin iosout,fio.seekg(),文件写入和文件读写,文件拷贝和文件
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++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)