[Langage] recuperation de donnees 'unsigned int' stockees dans un fichier
Bonjour,
J'ai pas su trouve dans la FAQ ou sur le forum de reponse a ma question: comment recuperer des donnees de type "unsigned int" stockees dans un fichier binaire (.bsq) a une position precise du fichier. j'ai applique la meme methode que pour recuperer des doubles (methode qui apres verification fonctionne correctement) en modifiant les types aux bons endroits...
Voici le code que j'utilise:
Code:
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
|
void readerForInt(string fileName, int iOffset,int paramSize, unsigned int *valuePtr)
{
cout<<" ======= reader for int ======="<<endl;
// declarations:
ifstream infile;
infile.open(fileName.c_str(),ios::in | ios::binary);
//fileName correspond au chemin absolu vers le fichier
concerne. ce fichier existe bien
//determine size of the file and block of interest:
infile.seekg(0, ios::end);
int endpos = infile.tellg(); // corresponds to the file size in bytes
int blockSize = sizeof(*valuePtr);
// determine the number of blocks of data inside the file:
int n = endpos/blockSize;
//curser positionning at the block of interest location:
int blockpos = (iOffset)*blockSize;
//read the data from the file:
// set the curser position in the file
infile.seekg(blockpos);
//cette partie pose probleme: la valeur rendue n'est pas celle
attendue:
// get the info from the file:
unsigned int* valUnsignedInt= new unsigned int [100];
cout<<"unsigned int size: "<<sizeof(unsigned int)<<endl;
infile.read(reinterpret_cast<char*>(valUnsignedInt) , paramSize );
*valuePtr = *valUnsignedInt;
cout<<" valUnsignedInt : "<<*valUnsignedInt<<endl;
delete[] valUnsignedInt;
} |
j'ai tente un autre cast avec (char *) au lieu de reinterpret_cast<char*> avec le meme resultat. je presume que le probleme se situe au niveau du cast, mais je ne sais pas comment y remedier.
quelqu'un peut il eclairer ma lanterne?
ps: le but est de recuperer un unsigned int a une position precise du fichier.
Merci d'avance