C ++写入文本文件问题 [英] C++ write to text file problem

查看:60
本文介绍了C ++写入文本文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是c ++的新手,但我一整天都在尝试搜索谷歌,我无法找到问题的答案,所以我想我会在这里试试。我正在尝试编写一个我输入到文本文件的字符串变量。我已经设法让它做到这一点,但是当程序重新加载它时会覆盖我在顶部的任何东西。我可以将第二次输入的内容放在文本文件的底部而不是顶部吗?


视觉示例*


<首次运行>







<第二次运行>









任何帮助将不胜感激。

I''m not exactly a newbie to c++, but i''ve been trying all day and searching around google and i couldnt find an answer to the problem so I thought i''d try here. I''m trying to write a string variable that i have input to the text file. I''ve managed to get it to do this, but when the program reloads it overwrites whatever I had at the top. Is it possible for me to have what I have entered the second time to be placed at the bottom of the text file instead of at the top?


Visual example*

<First run>
Cow
Dog
Pig

<Second run>
Sheep
Dog
Pig


Any help would be appreciated thanks.

推荐答案

对不起,不确定如何编辑以前的帖子。只是想我应该添加我想要发生的事情。








绵羊
Sorry, not sure exactly how to edit previous post. Just thought i should add what I wanted to happen.

Cow
Dog
Pig
Sheep




如果你在追加模式下打开文件,那么无论你写什么都到文件的末尾......


谢谢

Raghuram
Hi,
If you are opening the file in append mode then whatever u write goes to the end of the file...

Thanks
Raghuram





如果你在附加模式下打开文件,那么无论你写什么都写到文件的末尾...


谢谢

Raghuram
Hi,
If you are opening the file in append mode then whatever u write goes to the end of the file...

Thanks
Raghuram



感谢您的快速回复。你能指导我如何以追加模式打开文件吗?

Thanks for the quick response. Can you direct me exactly how to open the file in append mode?


这篇关于C ++写入文本文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆