zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    COGS 859. 数列
    9.7noip模拟试题
    hash练习
    9.6noip模拟试题
    9.5noip模拟试题
    poj 2117 Electricity
    洛谷P1993 小 K 的农场(查分约束)
    9.2noip模拟试题
    洛谷 P1273 有线电视网(dp)
    面试题收集
  • 原文地址:https://www.cnblogs.com/clc2008/p/2405386.html
Copyright © 2011-2022 走看看