Does not append if the file already exists

  append, c++, file

If the file does not exist, it will create and write to the file.
If the file does exist, it will not append/ write any data at all.

Customers selection1Input(Customers& UserStruct, fstream &file) // method used to allow user to input data into a structure                 will not append
{
    file.open("Customers.dat",  ios::app | ios::binary); // opens file to write (append) in binary mode

    cout << "Please enter your name. ";
    cin.getline(UserStruct.name, NAME_SIZE);

    cout << "Please enter your street address_1 ";
    cin.getline(UserStruct.streetAddress_1, STREET_SIZE);

    cout << "Please enter your street address_2 ";
    cin.getline(UserStruct.streetAddress_2, STREET_SIZE);

    cout << "Please enter your city ";
    cin.getline(UserStruct.city, CITY_SIZE);

    cout << "Please enter your state code / abreviation ";
    cin.getline(UserStruct.state, STATE_CODE_SIZE);

    cout << "Please enter your zip code ";
    cin >> UserStruct.zipCode;

    file.close(); // close file

    return UserStruct;
}

Source: Windows Questions C++

LEAVE A COMMENT