免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1440 | 回复: 3
打印 上一主题 下一主题

About the usage of ifstream and ofstream [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-08-20 15:56 |只看该作者 |倒序浏览
I have a TXT file with contents named test.txt as follow:
This is a test
444444
333333
good by!

I defined a ifstream variable named inFile and intialized with a string "test.txt", and I defined string outString and an ofstream variable named outFile with "output.txt" for initializing.I used the statements for coping the content of file test.txt into file output.txt as follow:
inFile >;>; outString;
outFile << outString;

but the content of the output.txt displayed as follow:
This is a test
Why? I need help.
Thank you!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2004-08-20 16:16 |只看该作者

About the usage of ifstream and ofstream

接getchar的返回值的类型错了吧?
int,不是char。

论坛徽章:
0
3 [报告]
发表于 2004-08-20 16:53 |只看该作者

About the usage of ifstream and ofstream

将程序做如下修改即可:

  1. // inFile >;>; outString;
  2. getline( inFile, outString );
  3. // outFile << outString;
  4. outFile << outString << "\n";
复制代码

以后要把问题描述清楚些(比如你给的结果就不正确,也不清楚你如何得到的。虽然可以猜出来)。最好贴上代码。

论坛徽章:
0
4 [报告]
发表于 2004-08-21 13:56 |只看该作者

About the usage of ifstream and ofstream

sorry,我的程序是这样的:
ifstream inFile("test.txt";
inFile >;>; outString;
ofstream outFile("output.txt";
outFile << outString;

在test.txt文件中的内容如下:
This is a test
444444
333333
good by!

执行上述语句后,output.txt中的内容如下:
This is a test
没有使用getline()funtion.
Thank you!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP