What am I doing wrong?

What am I doing wrong? I am trying to build a file to enter in information so I can retrieve it later but for some reason address line 1 and city keep showing up on the same line, HELP!!!


// This program is use to store structure variables
#include <iostream>
#include <fstream>
using namespace std;


// Make the array sizes
const int NAME_SIZE = 51, ADDRESS_SIZE = 51, CITY_SIZE = 51, STATE_SIZE = 4, ZIP_SIZE = 12, PHONE_SIZE = 14;

// Delcare a structure for record.
struct info
{
char name [NAME_SIZE];
int age;
char address1 [ADDRESS_SIZE];
char city [CITY_SIZE];
char state [STATE_SIZE];
char zip [ZIP_SIZE];
char phone [PHONE_SIZE];

};

int main ()
{
info person; // To hold info about a person
char again; // to hold Y or N.

//Open a file for binary output.
fstream people ("people.dat", ios::out | ios::binary);

do //starting my loop to get structure information.
{
// Get data about a person.
cout << "Enter the following data about a "
<< "a person:\n";
cout << "Name: ";
cin.getline (person.name, NAME_SIZE);
cout << "Age: ";
cin.ignore(); // This tells the program to skip over the remaining new line
cout << "Address line 1 (Include apart/suite numbers: ";
cin.getline (person.address1, ADDRESS_SIZE) ;
cout << "City: ";
cin.getline (person.city, CITY_SIZE);
cout << "State (Two letter Abbriviation only): ";
cin.getline (person.state, STATE_SIZE);
cout << "Zip Code (five digits only): ";
cin.getline (person.zip, ZIP_SIZE);
cout << "Phone(EX: XXX-XXX-XXXX): ";
cin.getline (person.phone, PHONE_SIZE);

// To write the contents of the person structure to a file is written next.
people.write(reinterpret_cast<char *>(&person),sizeof (person));

// Now ask the the loop to see if we want to add another oersons record.
cout << "Do you want to enter another person? ";
cin >> again;
cin.ignore(); //Skip over this line

} while (again == 'Y' || again == 'y');
// if anything elsed is press it will close file
people.close();
system ("PAUSE");
return 0;
}

Topic archived. No new replies allowed.