Ver Mensaje Individual
  #5 (permalink)  
Antiguo 21/11/2011, 17:48
sam90
 
Fecha de Ingreso: abril-2010
Ubicación: Rosario
Mensajes: 1.850
Antigüedad: 14 años, 11 meses
Puntos: 228
Respuesta: Trabajando con archivos

Código C++:
Ver original
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     //Declaramos los buffers y sus tamaños
  9.     char*buffer;
  10.     int length;
  11.     char*buffer2;
  12.     int length2;
  13.     char*buffer3;
  14.     //Almacenamos la foto en un buffer1 con su length1
  15.     ifstream in;
  16.     in.open("c:\\a1.jpg",ios::binary);
  17.                   in.seekg (0, ios::end);
  18.                   length = in.tellg();
  19.                   in.seekg (0, ios::beg);
  20.                   buffer = new char [length];
  21.                   in.read (buffer,length);
  22.                   in.close();
  23.       //Almacenamos la foto2 en buffer2 con su length2
  24.       ifstream in2;
  25.       in2.open("c:\\a2.jpg",ios::binary);
  26.      
  27.                   in2.seekg (0, ios::end);
  28.                   length2 = in2.tellg();
  29.                   in2.seekg (0, ios::beg);
  30.                   buffer2 = new char [length2];
  31.                   in2.read (buffer2,length2);
  32.                   in2.close();
  33.                  
  34.       //Guardamos las dos fotos en un archivo final, una detras de otra
  35.       ofstream out;
  36.       out.open("c:\\a3.jpg",ios::binary);
  37.       out.write(buffer,length);
  38.       //out.seekp (length);
  39.       out.write(buffer2,length2);
  40.       out.close();
  41.      
  42.       //Abrimos el archivo final,nos posicionamos en la 2 foto,la almacenamos
  43.       //en un buffer y la guardamos en final.jpg
  44.       buffer3 = new char[length2];
  45.       ifstream in3;
  46.       in3.open("c:\\a3.jpg",ios::binary);
  47.       in3.seekg(length, ios::beg);
  48.       in3.read(buffer3,length2);
  49.       in3.close();
  50.      
  51.       ofstream out2;
  52.       out2.open("c:\\a33.jpg",ios::binary);
  53.       out2.write(buffer3,length2);
  54.       out2.close();
  55.       return 0;
  56.       }

Asi si funciona!!