怎么打开一个txt文件并且每次都写入内容到文本文件的末尾

czbever 2011-02-23 12:05:09
怎么打开一个txt文件并且每次都写入内容到文本文件的末尾?
...全文
379 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
雪人2015 2011-02-24
  • 打赏
  • 举报
回复
STFW
breakerzy 2011-02-23
  • 打赏
  • 举报
回复
fopen 'a'
ofstream ios::app
Johnxme126 2011-02-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 delphiwcdj 的回复:]
C++代码

C# code

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("yourfile",ios::app);
if(!out) return 1;
char *info="hello\n";
out<<in……
[/Quote]

正解
isarc 2011-02-23
  • 打赏
  • 举报
回复
肯定有api可用的。我用的类对象只能用getfilesize,然后write(position,content);
delphiwcdj 2011-02-23
  • 打赏
  • 举报
回复
C++代码

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("yourfile",ios::app);
if(!out) return 1;
char *info="hello\n";
out<<info;

return 0;
}
bdmh 2011-02-23
  • 打赏
  • 举报
回复
fopen,用参数'a'打开,就是追加了
昵称很不好取 2011-02-23
  • 打赏
  • 举报
回复
ios::app Opens an output file for appending.
ios::ate Opens an existing file (either input or output) and seeks the end.
ios::in Opens an input file. Use ios::in as an open_mode for an ofstream file to prevent truncating an existing file.
ios::out Opens an output file. When you use ios::out for an ofstream object without ios::app, ios::ate, or ios::in, ios::trunc is implied.
ios::nocreate Opens a file only if it already exists; otherwise the operation fails.
ios::noreplace Opens a file only if it does not exist; otherwise the operation fails.
ios::trunc Opens a file and deletes the old file (if it already exists).
ios::binary Opens a file in binary mode (default is text mode).
昵称很不好取 2011-02-23
  • 打赏
  • 举报
回复
打开文件是指定追加格式就行了
czbever 2011-02-23
  • 打赏
  • 举报
回复
求c++实现
koolxiaoyuer 2011-02-23
  • 打赏
  • 举报
回复
CStdioFile fileGif;
//打开文件
fileGif.SeekToEnd(); //光标移到最后
fileGif.Write(/*参数1*/,(/*参数2*/); //忘了参数咋写了。1好像是字符,2是个数?

赵4老师 2011-02-23
  • 打赏
  • 举报
回复
摒弃fstream
使用FILE *
我在地球 2011-02-23
  • 打赏
  • 举报
回复
File fp;

fp=fopen("abc.txt","ab+");
smwhotjay 2011-02-23
  • 打赏
  • 举报
回复
c fopen a+标记. fwrite 不用设置文件指针.他在尾部追加写入
fulima007 2011-02-23
  • 打赏
  • 举报
回复
呵呵,老有人问这个问题

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧