文件问题

lixang000 2008-10-09 12:58:42
原来 执行outPut(..)后 我想要的是
a.txt内容 a.txt内容 a.txt内容
1234567 abc 1234567
abc

int main()
{
ofstream outFile("a.txt")
outPut(outFile);//此函数写入abc;
outFile.close();
}
outPut(...){ ..... outFile<<"abc"<<endl; ...... }
如何解决!
...全文
87 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
开心爸爸84 2008-10-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lixang000 的回复:]
那么
原来 执行outPut(..)后 我想要的是
a.txt内容 a.txt内容 a.txt内容
11111111 abc 11111111
0000000 abc
00000000


int main()
{
ofstream outFile("a.txt")
outPut(outFile);//此函数写入abc;
outFile.close();
}
outPut(...){ ..... outFile < <"abc" < <endl; ...... }
如何解决!
[/Quote]

把文件清空,重新写进去
lzr4304061988012 2008-10-11
  • 打赏
  • 举报
回复
这样的话,最好是输出到另一个文件.
lixang000 2008-10-11
  • 打赏
  • 举报
回复
那么
原来 执行outPut(..)后 我想要的是
a.txt内容 a.txt内容 a.txt内容
11111111 abc 11111111
0000000 abc
00000000



int main()
{
ofstream outFile("a.txt")
outPut(outFile);//此函数写入abc;
outFile.close();
}
outPut(...){ ..... outFile < <"abc" < <endl; ...... }
如何解决!
太乙 2008-10-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lann64 的回复:]
app方式打开
[/Quote]

汗~~原来想要这个啊!

那用fstream也行!



// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
fstream fs("t.txt",ios::app);
fs<<"123"<<endl;
fs.close();
return 0;
}


phz1985 2008-10-09
  • 打赏
  • 举报
回复

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile("abc.txt", ios::app);//以追加方式打开
outfile<<"abcdef";
outfile.close();
return 0;
}
jia_xiaoxin 2008-10-09
  • 打赏
  • 举报
回复
int main()
{
ofstream outFile("a.txt",ofstream::ate|ofstream::app);
outPut(outFile);//此函数写入abc;
outFile.close();
}
lzr4304061988012 2008-10-09
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
void outPut(ofstream & os)
{
os<<"abc" <<endl;
}

void main()
{
ofstream outFile("1.txt",ios::app);
outPut(outFile);//此函数写入abc;
outFile.close();
}
lann64 2008-10-09
  • 打赏
  • 举报
回复
app方式打开
Fighting Horse 2008-10-09
  • 打赏
  • 举报
回复
文件要用追加模式打开,改成这样就行了,ofstream outFile("a.txt", ios::app);
太乙 2008-10-09
  • 打赏
  • 举报
回复
没看懂需求!@

你想要的是
??

65,210

社区成员

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

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