Ver Mensaje Individual
  #3 (permalink)  
Antiguo 20/04/2009, 12:36
TinoFDW
 
Fecha de Ingreso: abril-2009
Mensajes: 9
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: Lectura/Escritura de datos

Gracias por la respuesta boli-sp.
He hecho el programa de prueba según la forma que me has indicado:
Código C++:
Ver original
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int a = 8765;
  8.     float b = 1.2345;
  9.     unsigned char c = 255;
  10.     ofstream ou2("2.txt", ios::out | ios::binary);
  11.     ou2 << a;
  12.     ou2 << b;
  13.     ou2 << c;
  14.     ou2.close();
  15.     //
  16.     ifstream in2("2.txt", ios::in | ios::binary);
  17.     int r; float t; unsigned char y;
  18.     in2 >> r;
  19.     in2 >> t;
  20.     in2 >> y;
  21.     in2.close();
  22.     cout << r << endl;
  23.     cout << t << endl;
  24.     cout << (int) y << endl;
  25. }
Sin embargo lo que pasa es que me lo escribe en formato texto y al leerlo no lo hace bien.

Última edición por TinoFDW; 20/04/2009 a las 12:46