Regardez ce petit code, il ouvrir un ifstream:problème avec ifstream
std::ifstream _fcs;
bool openFile(char* path)
{
istream::pos_type pos;
int tmp = 0;
_fcs.open(path, fstream::binary | fstream::in);
if(!_fcs.is_open())
return false;
tmp = 0;
pos = 0x404;
_fcs.seekg(0x404);
pos = _fcs.tellg(); /// return zero
_fcs >> tmp; ///
_fcs.read((char*)&tmp, 4);
return true;
}
j'ai deux problèmes. Après seekg, tellg renvoie zéro et quand je lis des données, il lit à partir du début du fichier
- Opérateur >> semble ne fonctionne pas. toujours retourner zéro!
//// ---------------------------------------- --------
merci pour votre attention. J'ai trouvé une solution dingue, mais je suis confus! si j'appelle deux fois seekg, cela fonctionne, voir ce code:
bool openFile(char* path)
{
istream::pos_type pos;
int tmp;
bool fail;
_fcs.open(path, fstream::binary | fstream::in);
if(!_fcs.is_open())
return false;
_fcs.seekg(0x402);
_fcs.seekg(0x402); /// When it comments, the tellg returns 0. am i crazy!?
fail = _fcs.fail();
assert(!fail);
pos = _fcs.tellg(); /// return 0x402!!!
/// _fcs >> tmp;
_fcs.read((char*)&tmp, 4);
return true;
}
vraiment, ce qui est arrivé?
//// -------------------------------------------- ----
s'il vous plaît aidez-moi ...
merci à l'avance.
oui, il existe. c'est un fichier binaire et aussi je l'ouvre avec un éditeur hexadécimal. Je veux lire ne pas écrire! :( – Mostafa
désolé, mal lu.utiliser istream :: lire puis –
je l'utilise, mais pourquoi le seekg ne change pas le pointeur get !!!! – Mostafa