#include <iostream>
#include <fstream>
using namespace std;
void EscribirFichCONFormato (const char *nombre);
void EscribirFichSINFormato (const char *nombre);
void LeerFichCONFormato (const char *nombre);
void LeerFichSINFormato (const char *nombre);
//implementacion de las funciones
void EscribirFichCONFormato (const char *nombre){
int n;
ofstream f (nombre);
while (cin>>n){
f<<n;
}
f.close();
}
void EscribirFichSINFormato (const char *nombre){
int n;
ofstream f (nombre, ios::binary);
cin>>n;
while(cin>>n){
f.write(reinterpret_cast<const char *>(&nombre),sizeof(nombre));
}
f.close();
}
void LeerFichCONFormato (const char *nombre){
ifstream f (nombre);
int n;
while(f>>n){
cout << n;
f>>n;
}
f.close();
}
void LeerFichSINFormato (const char *nombre){
int n;
fstream f(nombre, ios::in | ios::binary);
f.read(reinterpret_cast<char*>(&n),sizeof(n));
while (!f.eof()){
cout << n;
f.read(reinterpret_cast<char*>(&n),sizeof(n));
}
f.close();
}
int main () {
cout << endl << "Introduce numeros para rellenar el fichero CON formato (Ctrl+Z para acabar): ";
EscribirFichCONFormato("num01.txt");
cout << endl << "El fichero CON formato contiene los siguientes enteros" << endl;
LeerFichCONFormato("num01.txt");
cin.clear();
cout << endl << "Introduce numeros para rellenar el fichero SIN formato (Ctrl+Z para acabar): ";
EscribirFichSINFormato("num01.dat");
cout << endl << "El fichero SIN formato contiene los siguientes enteros" << endl;
LeerFichSINFormato("num01.dat");
system("PAUSE");
return 0;
}