Hi I have a text file of the format phonenumber housenumber firstname lastname
I'm trying to read all the data ans store it in an array. I have used the code below. But it is reading only first line data. Can anyone help me why this is happening.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#define Size 200
unsigned long long int mobilenumber[Size];
char seatnumber[Size][4];
char firstname[Size][30],lastname[Size][30];
using namespace std;
int main()
{
//delcares the files needed for input and output//
ifstream infile;
ofstream outfile;
infile.open("reservations.txt",ios::in);
//opens files needed for output//
outfile.open("pricing.txt");
int i=0;
if (infile.is_open())
{
infile>> mobilenumber[i]>>seatnumber[i]>>firstname[i]>>lastname[i];
i++;
numberofbooking++;
}
infile.close();
for(int i=0;i<=numberofbooking;i++)
{
cout<< mobilenumber[i]<<" "<< seatnumber[i]<<" "<< firstname[i]<<" "<< lastname[i];
}
return 0;
}
Thanks in advance
infile>> mobilenumber[i]>>seatnumber[i]>>firstname[i]>>lastname[i];you wantwhile (infile>> mobilenumber[i]>>seatnumber[i]>>firstname[i]>>lastname[i]) { i++; numberofbooking++;}