<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>Hola que tal.</DIV>
<DIV> </DIV>
<DIV>He hecho dos programillas, uno para escribir en un archivo binario los 
datos de una estructura, datos de variables miembro (no se si se diría así), 
luego posteriormente los quiero recuperar en otro código, pero no soy capaz, no 
alcanzo a ver lo que hago mal.</DIV>
<DIV> </DIV>
<DIV>Primero os pego el código del programa que crea el binario donde van los 
datos:</DIV>
<DIV> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">#include 
<fstream></FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">#include 
<iostream></FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">using namespace 
std;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">struct tficha {</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    char 
nombre[256];</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    long 
telefono;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
};</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">int main()</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">{</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    tficha 
ficha;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    int 
n;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    ofstream 
vfile;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
vfile.open("pruebas.dat", ios::binary);</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    for(n=0; 
n<=3; n++)</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
{</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        cout << 
"escriba su nombre: ";</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        cin >> 
ficha.nombre;</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        vfile << 
ficha.nombre;</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        cout << 
"escriba un telefono: ";</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        cin >> 
ficha.telefono;</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        vfile << 
ficha.telefono;</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        vfile.write((char 
*) &ficha, sizeof(ficha));</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
}</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
vfile.close();</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">}</FONT></DIV>
<DIV> </DIV>
<DIV>Luego aquí va el código del programa que debería leer esos datos:</DIV>
<DIV> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">#include 
<fstream></FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">#include 
<iostream></FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">using namespace 
std;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">struct tficha {</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    char 
nombre[256];</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    long 
telefono;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
};</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">int main()</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">{</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    tficha 
ficha;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    int 
n;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    ifstream 
vfile;</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
vfile.open("pruebas.dat", ios::in | ios::binary);</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
vfile.read((char *) &ficha, sizeof(ficha));</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    while 
(!vfile.eof())</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
{</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        cout << 
"nombre: " << ficha.nombre << endl;</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        cout << 
"telefono: " << ficha.telefono << endl;</FONT></DIV>
<DIV><FONT color=#333333 size=2 
face="Courier New">        vfile.read((char 
*) &ficha, sizeof(ficha));</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
};</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">    
vfile.close();</FONT></DIV>
<DIV><FONT color=#333333 size=2 face="Courier New">}</FONT></DIV>
<DIV> </DIV>
<DIV>Haber si me pueden aclarar por favor, un saludo y gracias.</DIV>
<DIV> </DIV>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<META name=GENERATOR content="LibreOffice 3.4  (Win32)">
<META name=CREATED content=20111024;9105492>
<META name=CHANGED content=20111024;9124326>
<STYLE type=text/css>
        <!--
                @page { margin: 2cm }
                p { margin-bottom: 0.21cm }
        -->
        </STYLE>

<P style="MARGIN-BOTTOM: 0cm"><FONT color=#548dd4><FONT 
face="Arial, sans-serif"><FONT size=2><I><B>Oscar Aparicio 
Holgado</B></I></FONT></FONT></FONT><BR><FONT color=#e36c09><FONT 
face="Tahoma, sans-serif"><FONT size=2>Administrador de 
sistemas.</FONT></FONT></FONT></P></DIV></DIV></DIV></BODY></HTML>