1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// declare a file pointer and open the cards file
ifstream cardInput("cards.txt");
if (!cardInput)
{
cout << "File cards.txt could not be opened. Fatal error." << endl;
exit(1);
}
cout << "File opened. Reading cards..." << endl;
// read the next line from the file
char Name[30];
char junk[5];
char phone[15];
int CardID = 0;
int temp = 0;
cardInput.getline(Name, 30, ',');
// tokenize the line to get the data for class variables
while (cardInput)
{
cardInput.getline(Name, 30, ',');
cardInput.getline(junk, 5, ',');
cardInput.getline(phone, 15, ',');
cardInput.getline(junk, 5, ',');
cardInput >> CardID >> temp;
Card working(Name, phone, CardID);
cards[i] = working;
i++;
}
cardInput.close();
|