lundi 13 avril 2020

Downloading data from a file

I need help with my function. It should download data from the file (personal data name, surname etc.) to the vector so when I want to add someone new it will be numerated form the last person (i have 3 people in the file, so when i will add someone new, the next one will have an id 4). Code below:

int downloadAddresseeInfo(vector <Addressee> &addressees)
{
Addressee addressee;
char sign = '|';
int addresseeCount= 0;
int numberOfSign = 0;
string partOfLine= "";

ifstream file;
file.open("KsiazkaAdresowa.txt",ios::in);

while(getline(file, partOfLine, sign ))
{
    switch(numberOfSign )
    {
    case 0:
        addressee.id = atoi(partOfLine.c_str());
        break;
    case 1:
        addressee.name = partOfLine;
        break;
    case 2:
        addressee.surname = partOfLine;
        break;
    case 3:
        addressee.telephone_number = partOfLine;
        break;
    case 4:
        addressee.email = partOfLine;
        break;
    case 5:
        addressee.address = wycinekpartOfLineLinii;
        break;
    }
    if(partOfLine== " ")
    {
        numberOfSign = 0;
        addressees.push_back(addressee);
    }
    else
    {
        numberOfSign ++;
    }

}
file.close();
return addresseeCount;
}

Aucun commentaire:

Enregistrer un commentaire