C++每日一练2.在文件末尾追加字符串

Posted 鱼酱2333

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++每日一练2.在文件末尾追加字符串相关的知识,希望对你有一定的参考价值。

需求:在文件末尾追加字符串

#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc,char **argv)

    string query;
    std::fstream in("c:/1.txt", ios::in|ios::out|ios::binary);

    //文件大小
    auto filesize = in.tellg();
    //移动到末端
    in.seekg (0, ios::end);
    //写文件
    in<<"123";
    //关闭
    in.close();

    return 0;


以上是关于C++每日一练2.在文件末尾追加字符串的主要内容,如果未能解决你的问题,请参考以下文章