如何在现有文本文件的末尾附加一些文本

时间:2014-01-31 15:22:14

标签: c++ file text append

如果可以,那么任何帮助都会很棒

我已经尝试过这段代码,

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 

1 个答案:

答案 0 :(得分:0)

您可能想要

fstream::out | fstream::app

而不只是fstream::app

你可以看一下:

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

要添加新行,请执行以下操作:

newBalance<<amount<<"\n";