I have a very basic question. I'm trying to read from a file that has data saved like this:
Collins, Bill
Smith, Bart
Allen, Jim
.
.
.
Holland, Beth
and I would like my code to read the data and save them into one column of an array. So what I did was,
#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
string first, last, FIRST[200], LAST[200];
ifstream infile;
infile.open("names.dat");
while (!infile.eof())
{
for (int i = 0; i < !infile.eof(); i++)
{
infile >> first;
FIRST[i] = first;
cout << FIRST[i] << " ";
infile >> last;
LAST[i] = last;
cout << LAST[i] << " " << endl;
}
}
return 0;
}
However, I want just one array named NAME[], not two(FIRST[] & LAST[]). So basically if I call NAME[0] would be Collins, Bill.
I really don't know how to do this... reading sources makes me even more confused..
This is just a little part of the entire program that I have to write, which is sorting names alphabetically and I haven't even passed this stage yet.