Fstream and store data in arrays

Hello everyone

i'm new C++ lover :)

how i can store specific data type from text file in multiple arrays for each type ??

like string array fore first names also anther one for last name and double array for mobile numbers !
text file example :|


**********************
Sami Albert 2789645421
Sarah Jackson 475484459
John Omar 6792144459
***********************

the Array s will be looks like

/*
string Fname[10];

string Lname[10];

long Num[10];
*/
Make a for loop going from 0 to SIZE-1 of the array, and read from the file into each of the three arrays at index i.

1
2
3
4
5
for(int i = 0; i < 10; i++)
{
      // read first name, last name, and num into i-th position of array
     file >> Fname[i] >> Lname[i] >> Num[i];
}
empty
Last edited on
You should remove the getline (line 28), otherwise you skip lines, and change the type of ID to unsigned long long, because the numbers in your file don't fit in a 32 bit long (if long is 32 bit on your compiler)
Topic archived. No new replies allowed.