Strange character in C++ program output
<p>I am creating an ATM program in C++ for school and I'm using this project as an opportunity to begin learning the language.  I am trying to output bank accounts to a text file in this format:</p>

<pre><code>First Last  
CardNumber  
PinNumber  
Balance
</code></pre>

<p>Originally it was outputting fine and then I developed a bunch of new methods etc.  I didn't change any of the original code that has to do with outputting the bank account but now it's outputting strangely.</p>

<p>My output ends up being:</p>

<pre><code>First Last  
random letter or symbol  
PinNumber  
blank  
</code></pre>

<p>Here is my code for creating a new bank account:</p>

<p>AccountHandler.h</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

struct bankAccount //Create a new bank account type
{
string name;
string cardNum;
string balance;
string pin;
};



class AccountHandler
{
public:

    AccountHandler();
    ~AccountHandler();
    void withdraw(struct bankAccount acc, string amount);
    void deposit(struct bankAccount acc);
    int checkBalance(struct bankAccount acc);
    void createAccount();


};
</code></pre>

<p>AccountHandler.cpp</p>

<pre><code>void AccountHandler::createAccount() //creates a new bank account and stores in accounts.txt
{
ofstream accounts;
struct bankAccount newAcc;
string first, last;
string tempPin1, tempPin2;

if (!accounts.is_open())
{
    accounts.open("accounts.txt", ofstream::app);
}

std::cout &lt;&lt; "Thank you for choosing to bank with ATM406!\n\n";
std::cout &lt;&lt; "Please enter the name for the account: ";
std::cin &gt;&gt; first &gt;&gt; last;
newAcc.name = first + " " + last;

while (true)
{

    std::cout &lt;&lt; "\nPlease enter a 4-digit pin for security: ";
    std::cin &gt;&gt; tempPin1;

    std::cout &lt;&lt; "\nPlease re-enter your 4-digit pin for validation: ";
    std::cin &gt;&gt; tempPin2;

    if (tempPin1 == tempPin2) //PINS MATCH
    {
        newAcc.pin = tempPin1;
        break;
    }
    else //PINS DO NOT MATCH
    {
        std::cout &lt;&lt; "The pins did not match!" &lt;&lt; std::endl;
    }

}

//GENERATE A RANDOM 4-DIGIT NUMBER FOR CARDNUM

srand(time(NULL));
newAcc.cardNum = rand() % 9000 + 1000;


//STORE ACCOUNT IN FORMAT: NAME\nCARDNUM\nPIN\nBALANCE

accounts &lt;&lt; newAcc.name &lt;&lt; "\n" &lt;&lt; newAcc.cardNum &lt;&lt; "\n" 
    &lt;&lt; newAcc.pin &lt;&lt; "\n" &lt;&lt; newAcc.balance &lt;&lt; "\n";

accounts.close();

std::cout &lt;&lt; "\nAccount created with name: " &lt;&lt; newAcc.name &lt;&lt; "  pin: " &lt;&lt; newAcc.pin
    &lt;&lt; ". Card number: " &lt;&lt; newAcc.cardNum &lt;&lt; "\n\n\n";


}
</code></pre>

<p>Thank you!</p>