C++简单文件操作
View Code #include?"stdafx.h"
#include<fstream>
#include?<iostream>
using?namespace?std;
int?_tmain(int?argc,?_TCHAR*?argv[])
{
????//文件寫入操作
????/*int?s=0;????
????ofstream?fileout("a.doc");
????if(!fileout){
????????cout<<"文件打開失敗"<<endl;
????}
????while(s<=10){
????????fileout<<s<<"+1="<<++s<<endl;
????}
????cout<<"寫入成功"<<endl;
????fileout.close();*/
????char?ch;
????ofstream?f2;
????f2.open("D:\\data2.txt");//默認ios::out?不存在則創建
????if(!f2){
????????cerr<<"錯誤"<<endl;
????????exit(1);
????}
????while((ch=cin.get())!=EOF)//Ctrl+Z?組合?代表文件結束符EOF
????{
????????f2<<ch;????????
????????//f2.put(ch);
????}
????f2.close();
????int?a;
????cin>>a;
????return?0;
}
#include<fstream>
#include?<iostream>
using?namespace?std;
int?_tmain(int?argc,?_TCHAR*?argv[])
{
????//文件寫入操作
????/*int?s=0;????
????ofstream?fileout("a.doc");
????if(!fileout){
????????cout<<"文件打開失敗"<<endl;
????}
????while(s<=10){
????????fileout<<s<<"+1="<<++s<<endl;
????}
????cout<<"寫入成功"<<endl;
????fileout.close();*/
????char?ch;
????ofstream?f2;
????f2.open("D:\\data2.txt");//默認ios::out?不存在則創建
????if(!f2){
????????cerr<<"錯誤"<<endl;
????????exit(1);
????}
????while((ch=cin.get())!=EOF)//Ctrl+Z?組合?代表文件結束符EOF
????{
????????f2<<ch;????????
????????//f2.put(ch);
????}
????f2.close();
????int?a;
????cin>>a;
????return?0;
}
轉載于:https://www.cnblogs.com/clc2008/archive/2012/03/19/2405386.html
總結
- 上一篇: [原]android2.3如何使用Sha
- 下一篇: 淡淡说说技术人员创业