0
이것은 내 보증금입니다. (currentBalance)에있는 값을 텍스트 파일 호출 균형에 저장하려고합니다. 지금 나는 단 하나의 문장을 "파일 1에 쓰는 것"을 저장하는 것을 알고 있습니다. 새 줄에 쓰고 싶습니다. 다시 쓰지 않습니다.텍스트 파일의 새 행에 myfile에 값을 저장하십시오.
하지만 마지막 3 개의 입금액 만 저장하고 싶습니다. 나중에 입금 내역 3 개를 볼 수 있기를 바랍니다.
float deposit(int y, int x)
{
cout<<"\n"<<endl;
cout<<"Welcome to the deposit area"<<endl;
cout<<"Enter a sum you wish to add to your account:";
cin>> y ;
currentBalance = y + x ;
cout << "Your new balance is:" << currentBalance <<endl;
ofstream myfile;
myfile.open ("balance.txt");
myfile << "Writing this to a file1.\n";
myfile.close();
cout<<"\n"<<endl;
cout<<"Press 0 for further action or press 9 to exit." <<endl;
cin >> option;
if (option == 9)
{
exit(0);
}
else if (option == 0)
{
return 1;
}
else
{
exit(0);
}
}
무엇을 현재 잔액에 저장합니까?
이것은 내 잔액 코드입니다. 당신이 파일에 추가 곳으로 만들 것
float balance(int x)
{
cout<<"Welcome to the balance area"<<endl;
cout<< "Your balance is: " <<(char)156 <<endl;
string line;
ifstream myfile ("balance.txt");
if (myfile.is_open())
{
while (getline (myfile,line))
{
cout << line << '\n';
}
myfile.close();
}
가능한 중복 [C++에서 텍스트 파일에 텍스트를 추가하는 방법?] (http://stackoverflow.com/questions/2393345/how-to-append-text-to-a-text -file-in-c) –
무엇을 변경해야합니까? –
myfile << "이것을 파일 1에 쓰십시오. \ n"; .... to myfile << currentBalance; –