C++如何从文本结尾开始输入

来源:百度知道 编辑:UC知道 时间:2024/07/03 10:53:27
帮帮忙呀 ofstream 怎么才能 不替换原有文本做到从上次结束的地方输入呢

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

#define OK 1

int main(void)
{
char buf[1024];
ofstream tfile("data.txt",ios_base::app);
//ios_base::app这个就是在文件尾添加数据
cout<<"Input the string:";
cin>>buf;
cout<<buf;
tfile.write(buf,strlen(buf));
return OK;
}

std::ofstream file("xyz.out", std::ios::out|std::ios::app);
app表示append,就是追加的意思

100分啊 我怎么没看到

fseek(filename* ,0,SEEK_END);//定位文件指针到文件的末尾处
然后再开始文件操作

先把文件指针移动到最后,去看看SEEK函数吧.