Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/11/2008, 03:10
pacorubio77
 
Fecha de Ingreso: noviembre-2007
Mensajes: 533
Antigüedad: 16 años, 6 meses
Puntos: 1
¿como se almacena un registro en un vector,leyendo un fichero?

YO QUIERO ALMACENAR UN REGISTRO EN UN VECTOR DE REGISTROS,PERO LO HAGO MAL

Hola,mirar yo tengo en un fichero lo siguiente:

1 b c
2 a b
....

cada linea es un registro
struct Tregistro{
int origen;
char simbolo;
int destino;
};

y ahora quiero segun vaya leyendo ir metiendo en mi vector de registros Tregistro vector[100];

en la linea vector[i]=aux....creo que está el error,el codigo es el siguiente:

Código:
# struct Tregistro{
#     int origen;
#     char simbolo;
#     int destino;
#  
# };
# Tregistro vector[100];
#  
# void LeerFichero(char fichero[]){
#  
#     fstream fic;
#     string linea;
#     Tregistro aux; 
#     int i=0;
#     fic.open(fichero,ios::in);
#    
#     if(!fic){
#  
#         cout<<"error,apertura del fichero"<<endl;
#     }
#     else{
#         //cout<<"aqui"<<endl;
#         //getline(fic,linea);
#         //cout<<linea<<endl;
#         fic.read((char*)&aux,sizeof(Tregistro));
#         while(!fic.eof()){
#             vector[i]=aux;
#             //cout<<"y aqui"<<endl;
#             cout<<vector[0].origen<<endl;
#             //getline(fic,linea);
#             //cout<<linea<<endl;
#             fic.read((char*)&aux,sizeof(Tregistro));
#         i++;   
#         }
#        
#     }
#     fic.close();
# }
ALGUIEN ME PUEDE AYUDAR???