Как добавить текст в конец существующего текстового файла

0

Если это возможно, любая помощь будет большой

Я уже пробовал этот код,

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 
Теги:
file
text
append

1 ответ

0

Вы можете поставить

fstream::out | fstream::app

вместо просто fstream::app

Вы можете посмотреть:

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

Чтобы добавить новую строку, выполните:

newBalance<<amount<<"\n";
  • 0
    Но это ничего не меняет, следующая сумма будет по-прежнему рядом с предыдущей
  • 0
    о, я пропустил, что у вас нет << "\ n" извините.
Показать ещё 2 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню