bushin Posted December 30, 2009 at 09:59 PM Report Share #303324 Posted December 30, 2009 at 09:59 PM olá pessoal! Estou com o seguinte problema, quando elimino um utilizador, com esta função: void eliminaUtilizador(int tipo){ Utilizador* usr; int id=0; switch(tipo){ case ADMINISTRADOR: usr=new Administrador(); break; case FUNCIONARIO: usr=new Funcionario(); break; case CLIENTE: usr=new Cliente(); break; } cout<<"Introduza o id do Utilizador a eliminar: "; cin>>id; usr->erase(id); delete usr; } quando peço para listar os utilizadores, void listaUtilizadores(int tipo){ Utilizador* usr; ifstream file; switch(tipo){ case ADMINISTRADOR: usr=new Administrador(); break; case FUNCIONARIO: usr=new Funcionario(); break; case CLIENTE: usr=new Cliente(); break; } int num=usr->getLastID(); for(int i=0;i<num;i++){ usr->read(i+1); cout<<usr->toString()<<endl; cout<<" ----------------------------------------------------------------- "<<endl; } } ele lista-me os que eliminei, melhor ele apaga os dados do id que pedi mas deixa os enunciados. ex: numero: 8 Nome: telefone: -112247834 utilizador: Pass: Conseguem ver qual é o problema??? Link to comment Share on other sites More sharing options...
bushin Posted January 7, 2010 at 01:36 AM Author Report Share #304569 Posted January 7, 2010 at 01:36 AM não há ninguém k me possa ajudar????????????? Link to comment Share on other sites More sharing options...
TheDark Posted January 7, 2010 at 10:15 AM Report Share #304585 Posted January 7, 2010 at 10:15 AM Sem saber o que fazem os métodos read e erase, e provavelmente mais uma data de detalhes, é complicado ajudar. Desaparecido. Link to comment Share on other sites More sharing options...
bushin Posted January 10, 2010 at 04:57 AM Author Report Share #305158 Posted January 10, 2010 at 04:57 AM Penso que o meu problema está nesta função: int Utilizador::getLastID(){ ifstream file(ficheiro,ios_base::in); string linha; int lastID=0; while(!file.eof()){ file>>linha; } linha=linha.substr(0,linha.find_first_of(';',0)); lastID=atoi(linha.c_str()); file.close(); return lastID; } Preciso de actualizar ou melhor preciso de saber quantos id (linhas de registo) tenho no ficheiro. Para poder utilizar for(int i=0;i<num;i++){ usr->read(i+1); cout<<usr->toString()<<endl; cout<<" ----------------------------------------------------------------- "<<endl; Se não, vai me buscar o total de utilizadores quer os que já foram apagados quer os que realmente estão activos. string Utilizador::toString(){ stringstream s; s<<"Numero:\t\t"<<id<<endl<<"Nome:\t\t"<<nome<<endl<<"Morada:\t\t"<<morada<<endl; s<<"Codigo Postal:\t"<<cPostal<<endl<<"Localidade:\t"<<localidade<<endl<<"Telefone:\t"<<telefone<<endl; s<<"Utilizador:\t"<<UID<<endl<<"Password:\t"<<password<<endl; return s.str(); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now