1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| #include <fstream>
#include <iostream>
using namespace std;
char* lire(const char* nomfichier)
{
int size;
char * memblock = NULL;
ifstream file (nomfichier, ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
//POUR TESTER LA TAILLE DE CE QUE J'ECRIS DANS LE FICHIER
cout << "size in read : " << size << endl;
memblock = new char [size];
file.seekg (0, ios::beg);
//LECTURE DU FICHIER AVEC LA BONNE TAILLE VERIFIEE PLUS HAUT
file.read (memblock, size);
//ICI RIEN NE VA PLUS.... WTF
cout << memblock << " : " << std::char_traits<char>::length(memblock) << '\n' << endl;
file.close();
}
else cout << "Unable to open file";
return memblock;
}
void ecrire(const char* nomfichier, const char* data)
{
int size;
std::ofstream file (nomfichier, ios::out|ios::binary);
//TEST DE LA TAILLE EN ECRITURE -> OK
size = std::char_traits<char>::length(data)+1;
cout << "size in write : " << size << endl;
file.write (data, size);
file.close();
}
int main(int argc, char *argv[])
{
char* data;
uint64_t* ui64;
ui64 = new uint64_t(77);
data = reinterpret_cast<char*>(ui64);
//TEST DE LA DONNEE ET DE SA TAILLE
cout << data << " : " << std::char_traits<char>::length(data) << '\n' << endl;
ecrire("test.txt", data);
data = lire("test.txt");
//LA REINTERPRETATION NE FONTIONNE PAS!!!
*ui64 = reinterpret_cast<uint64_t>(data);
cout << *ui64 << '\n' << endl;
*ui64 = data[0];
cout << *ui64 << '\n' << endl;
cout << data << '\n' << endl;
return 0;
} |
Partager