Having trouble reading in new data into fstream

I am constructing a program that is basically a bank app. I know how to read in NEW "accounts" into a fstream file but the second option is to enter transactions into an EXISTING account. So far I was able to verify that the account (file) exists, but every time I try and just add data to the existing data, it ends up all mixed up and not at all what I want. I've tried fstream::app but I don't think I'm using it correctly. The following code is what I currently have but I've tried different ways also. (Sorry code is long)

int accountNumber;
string date, description;
float ammount;
string suffix=".dat";

cout << endl << "ACCOUNT TRANSACTION" << endl << endl;

//Checking if account exists
cout << "Enter your 3-digit account number: ";
cin >> accountNumber;

stringstream ss;
ss << accountNumber << ".dat";
string filename = ss.str();

fstream inB;

if (inB.fail())
cout << endl << "ERROR: That account does not exist." << endl;


cout << "Enter the date (mm/dd/yyyy): ";
cin >> date;

cout << "Enter transaction title: ";
cin >> description;

cout << "Enter transaction ammount : $";
cin >> ammount;

fstream outB;
outB.open(filename.c_str(), fstream::app);

outB << endl << date << endl << description << endl << ammount << endl;


//read new file back out (test)
stringstream ss;
ss << accountNumber << ".dat";
string filename = ss.str();
string line;

ifstream inB;

if (inB.is_open())
while ( getline(inB, line))
cout << line << endl;

How does the input file look like ?
How does the output look like ?
How should the output look like ?
I actually figured it out. I changed my code to:

cout << "Enter transaction title: ";
getline(cin, description);

instead of:

cout << "Enter transaction title: ";
cin >> description;

and it actually fixed my problem. I don't understand why. But here is the full instructions for what I was trying to accomplish: :

If the user selects B., request the Account Number, Date, Description, and Amount from the user. Open the file with the file name “xxx.dat” where xxx is the Account Number requested from the user. If the file does not open, alert the user and return to the menu. The file should be opened in read/write mode and set to append data so as to not overwrite existing data. Read the last line in the file, which should be the balance of the account the last time a transaction was added. Write the Date, Description, Amount, and calculated new balance, each of these four data elements on a separate line in the file. The calculated new balance can be found from the balance read from the file plus/minus the Amount. Close the file. Return to the menu. As an example, when step 3 is complete, the file might look like:

Initial Deposit
Titan Bookstore Online -245.67
Last edited on
Registered users can post here. Sign in or register to post.
<rt id="pwjBlLZ"><small id="pwjBlLZ"></small></rt>
<acronym id="pwjBlLZ"></acronym><rt id="pwjBlLZ"></rt>
<tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr><tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr><acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym>
<acronym id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></acronym>
<option id="pwjBlLZ"></option>
<tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr>
<acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym><acronym id="pwjBlLZ"></acronym>
<acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym>
  • 6512882421 2018-04-19
  • 4659652420 2018-04-19
  • 2967832419 2018-04-19
  • 8339042418 2018-04-19
  • 8147112417 2018-04-19
  • 2774752416 2018-04-19
  • 4316132415 2018-04-19
  • 6265742414 2018-04-19
  • 1875142413 2018-04-19
  • 4146552412 2018-04-19
  • 8205662411 2018-04-19
  • 959982410 2018-04-19
  • 7153742409 2018-04-19
  • 9349932408 2018-04-18
  • 6024052407 2018-04-18
  • 2113432406 2018-04-18
  • 7629172405 2018-04-18
  • 163882404 2018-04-18
  • 3515922403 2018-04-18
  • 5047802402 2018-04-18