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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
/*
this program tests some get line stuff for sadistic fun.
*/
#include <iostream>
#include <fstream>
using namespace std;
const int SIZE_LIMIT = 20;
const int NAME_SIZE = 20;
const int AGE_SIZE = 2;
const int WEIGHT_SIZE = 5;
struct Person
{
char fullName[NAME_SIZE];
int age;
char hobby[NAME_SIZE];
double weight;
};
typedef Person DatingSite[NAME_SIZE];
void LoadFile(fstream&, int&, DatingSite);
int main()
{
int count = 0;
DatingSite Bachelor;
fstream testFile;
LoadFile(testFile, count, Bachelor);
return 0;
}
void LoadFile(fstream &File, int &count, DatingSite Bachelor)
{
File.open("test.txt", ios::in);
do
{
if (File.eof() || File.fail() || File.bad())
break;
File.getline(Bachelor[count].fullName, NAME_SIZE, ',');
File >> Bachelor[count].age, AGE_SIZE;
File.ignore(1);
File.getline(Bachelor[count].hobby, NAME_SIZE, ',');
File >> Bachelor[count].weight;
File.ignore(1);
cout << Bachelor[count].fullName << endl;
cout << Bachelor[count].age << endl;
cout << Bachelor[count].hobby << endl;
cout << Bachelor[count].weight << endl;
cout << "The count is " << count << endl;
count++;
} while(!File.eof());
}
|