Thread: File Reading!
View Single Post
Old 08-20-2005, 02:03 PM   #5 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
3rd Time Lucky

As part of the functionality for a college assignment, I am trying to read two variables from a file. These being the following:
  • Name - this will store the persons name
  • House - this will store a house number

This is currently working, but i would like the user to load another name & house number that is stored within the file, upon pressing the ‘n’ key on their computer’s keyboard.

How can this be done?
See coding so far below.

Many Thanks

Code:
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <conio.h>
#include <dos.h>

int main (void)
{
  char name[50];
  int house[2];
  char choice;

  do
  {
    choice = 1;
    cin >> choice;

    ifstream data (".\\records.txt");
    data >> name;
    data >> house;
    cout << name;
    cout << house;
    data >> name;
    data >> house;
    data.close();
  } while (choice == 'n');
  delay(5000);
  return 0;
}
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote