Pregunta: | 27897 - COMO CREO UN ARCHIVO.DAT EN VISAUL C++ 6.0 |
Autor: | José Giraldo Susoni |
Hola.. Estoy queriendo hacer un registro de datos y quiero guardarlo en mi disco duro ya no en mi memoria , estuive leyendo algo sobre la lbreria fstream ; pero no entiendo muy bien. Necesito los pasos adecuados mo crear esta estructura en un archivo .dat;
struct sRegistro { char nombre[40]; int edad; }; sRegistro alumnos; ... y de ahí que hago ayuda por favor....??? |
Respuesta: | Morello_cl |
Ejemplo
Para Leer ======== sRegistro alumno; fstream iofile("archivo.dat", ios::binary | ios::in | ios::out); //Buscamos el alumno numero 10 iofile.seekg(9 * sizeof(sRegistro)); iofile.read((char *)&alumno, sizeof(sRegistro)); iofile.close(); Para Escribir //Agregamos el usuario en el primer registro iofile.seekg(0); iofile.write((char *)&alumno, sizeof(sRegistro)); |