【问题标题】:How to append some text at the end of an existing text file如何在现有文本文件的末尾附加一些文本
【发布时间】:2014-02-24 08:30:05
【问题描述】:

如果这是可能的,那么任何帮助都会很棒

这个代码我已经试过了,

float deposit (float balance)
{


     double amount; 
    system("cls");
    cout<<"Enter the amount you wish to deposit"<<endl; 
    cin>>amount; 


    ofstream newBalance;                        
    newBalance.open ("deposit.txt", fstream::app);
    newBalance<<amount; 
    newBalance.close();

    balance = balance + amount; 
    writeBalance(balance); 
    return balance;  
}
//This is a function to allow the user to increase their balance 

【问题讨论】:

标签: c++ file text append


【解决方案1】:

你可能想放

fstream::out | fstream::app

而不仅仅是fstream::app

你可以看看:

http://www.cplusplus.com/reference/fstream/fstream/open/

要换行,只需:

newBalance<<amount<<"\n";

【讨论】:

  • 但这并没有改变任何事情,下一个金额仍将紧邻上一个
  • 哦,我错过了你没有
  • yh 但这只会漏掉一行,我希望它一遍又一遍地漏掉一行,而不仅仅是一次
  • 所以你第一次只进入下一行?您不能只修改文件,就好像它是一个 htmo 文本区域,只需将其读入,然后写出对最后一行进行更改的文件
猜你喜欢
  • 2011-04-13
  • 1970-01-01
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 2011-09-06
相关资源
最近更新 更多