Skip to content

Instantly share code, notes, and snippets.

@luistelmocosta
Created December 23, 2015 04:18
Show Gist options
  • Save luistelmocosta/8ceab45ad1c68d308267 to your computer and use it in GitHub Desktop.
Save luistelmocosta/8ceab45ad1c68d308267 to your computer and use it in GitHub Desktop.
void Campeonato::readFileBilhetes(string filename) {
fstream infile(filename.c_str());
string linha, dono;
int dia, mes, ano;
vector<int> campeonatoIds;
BSTItrIn<Prova> it = calendario->getProvas();
vector<Prova*> tmp;
while (getline(infile, dono)) // get name and check status file stream
{
cout << dono << endl;
// read in date
getline(infile, linha);
istringstream iss (linha);
string tmpstr1;
getline(iss, tmpstr1, '/');
dia = atoi(tmpstr1.c_str());
getline(iss, tmpstr1, '/');
mes = atoi(tmpstr1.c_str());
getline(iss, tmpstr1, '/');
ano = atoi(tmpstr1.c_str());
cout << dia << "/" << mes << "/" << ano << endl;
date d;
if(dia < 1 || dia > 31|| mes < 1 || mes > 12 || ano < 1 || (dia > 28 && mes == 2) || (dia > 30 && mes == 4) || (dia > 30 && mes == 6) || (dia > 30 && mes == 9) || (dia > 30 && mes == 11)){
cout << "Data invalida!";
}
else{
d.dia = dia;
d.mes = mes;
d.ano = ano;
}
// read in provas ids
getline(infile, linha);
istringstream iss2(linha);
string tmpstr2;
while (getline(iss2, tmpstr2, ','))
{
unsigned int provaID = atoi(tmpstr2.c_str());
if(it.retrieve().getID() == provaID) {
/*cout << "ola" << endl;
for(unsigned int i = 0; i < provasCampeonato.size(); i++) {
cout << "aqui" << endl;
if(provasCampeonato[i]->getID() == provaID) {
cout << provasCampeonato[i];
tmp.push_back(provasCampeonato[i]);*/
}
else
continue;
//campeonatoIds.push_back(atoi(tmpstr2.c_str()));
}
cout << endl;
Adepto *a1 = new Adepto(dono);
Bilhete *b1 = new Bilhete(d, a1, tmp);
inserirBilhete(*b1);
tmp.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment