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;
    }
  • 相关阅读:
    模型层
    视图层,模板层
    ORM表关系建立
    CMakeList入门
    C++标准模板库
    C++基本语法
    g++应用说明
    Linux快捷键
    Git 操作备忘
    Block的详细介绍
  • 原文地址:https://www.cnblogs.com/Fred1987/p/14744380.html
Copyright © 2011-2022 走看看