Hi guys I'm trying to do a while loop since this afternoon for the code below but was unsuccessful. I'm reading from a file A family name and the number then the names belong to the family which will be like this
JAMES SMITH
MARY SMITH
JOHN SMITH
ROBERT JOHNSON
PATRICIA JOHNSON
MICHAEL JOHNSON
LINDA JOHNSON
WILLIAM JOHNSON
It reads the first one then stop. what is the best way to do the loop in this case:
I have a header file but I don't think there is a problem with it so I didn't include the file.
Here is a sample from the file that I'm reading from
-------------------------
SMITH 3
JAMES
MARY
JOHN
JOHNSON 4
PATRICIA
MICHAEL
LINDA
WILLIAM
-------------------------
#include <iostream>
#include <fstream>
#include <string>
#include "dynamicArray.h"
using namespace std;
int main()
{
int i=0;
int size;
string family;
ifstream fin("all.txt");
ofstream fout("OUT.txt");
int j=0;
fin>>family;
fin >> size;
dynamicArrayClass myArray(size) ;
while(i<size && fin >> myArray[i])
i++;
for(i=0;i<myArray.getNumNames();i++)
cout << myArray[i] << " "<<family<<endl;
return 0;
}