zoukankan      html  css  js  c++  java
  • C++ append file via ofstream

    #include <iostream>
    #include <fstream>
    #include <string>
    #include <conio.h>
    
    using namespace std;
    
    void writeFileDemo5()
    {
        ofstream writeFile("writeFile7.txt",std::ios::app);
        if (!writeFile.is_open())
        {
            cout << "Create writeFile2.txt failed! " << endl;
            return;
        }
    
        char str[10000];
        char ch;
        while ((ch=_getch())!=27)
        {
            cin.getline(str, 10000);
            writeFile << str << endl;      
        }
        cout << "Over" << endl;
        writeFile.close();
        cout << "Finished!" << endl;
    }
    #include <iostream>
    #include <ostream>
    #include <istream>
    #include <fstream>
    #include <conio.h>
    using namespace std;
    
    void ostreamDemo6()
    {
        ofstream writeFile;
        writeFile.open("WriteFile6.txt", std::ios_base::app);
        if (writeFile.is_open())
        {
            char str[10000];
            char ch;
            while (1)
            {
                cin.getline(str, 10000);
                ch = _getch();
                if (ch != 27)
                {
                    writeFile << str << endl;
                }
                else
                {
                    cout << "Over" << endl;
                    break;
                }
            }
        }
        writeFile.close();
        cout << "Finished" << endl;
    }
  • 相关阅读:
    koa2环境搭建
    单例模式
    nodejs fs path
    path node
    webpack code splitting
    babel 插件编写
    C#验证码类
    C#身份证识别相关技术
    C# Socket服务端与客户端通信(包含大文件的断点传输)
    动态抓取网页信息
  • 原文地址:https://www.cnblogs.com/Fred1987/p/14744380.html
Copyright © 2011-2022 走看看