since you have a known format with with data separated by white spaces, we can create an object to hold each line from the text file:
struct account
{
//string string char int double string
string first_name;
string last_name;
char m_f;
int age;
double balance;
string address;
};
Now you can load a text file into a data structure of your choice:
vector<account> account_list;
account temp;
while(infile)
{
infile >> temp.first_name;
infile >> temp.last_name;
infile >> temp.m_f;
infile >> temp.age;
infile >> temp.balance;
//since we need to include the white spaces with the address data...
getline(infile, temp.address);
//load the data structure
account_list.push_back(temp);
}
Here is a simple function to display the data:
void display(vector<account> account_list)
{
cout << "\n\tFirst\tLast\tGender\tAge\tBalance\tAddress"
<< "\n\t--------------------------------------------------------";
for(int i=0, size=account_list.size(); i<size; i++)
{
cout << account_list[i].first_name << '\t';
cout << account_list[i].last_name << '\t';
cout << account_list[i].m_f << '\t';
cout << account_list[i].age << '\t';
cout << account_list[i].balance << '\t';
cout << account_list[i].address << '\t';
cout << endl;
}
} Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118