Problèmes lors de la lecture d'un fichier
Bonjour,
Voila j'ai un énorme (enfin tou tdu moins déroutant) problème sur un truc aussi idiot que la lecture d'un fichier :oops:
Le fichier "essai" que je veux lire contient 10 fois cette même ligne :
"abcdefghijklmnopqrstuvwxyz"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ifstream inVF("essai", ios::in);
inVF.seekg(0, ios::beg );
long position = 0;
while(!inVF.eof())
{
string chaineVF;
position = inVF.tellg();
getline(inVF, chaineVF);
cout<<"## chaineVF : "<<chaineVF<<endl;
cout<<"## position : "<<position<<endl;
}
inVF.close();
return 0;
} |
sortie console :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
## chaineVF : abcdefghijklmnopqrstuvwxyz
## position : 0
## chaineVF : ijklmnopqrstuvwxyz
## position : 36
## chaineVF : hijklmnopqrstuvwxyz
## position : 63
## chaineVF : ghijklmnopqrstuvwxyz
## position : 90
## chaineVF : fghijklmnopqrstuvwxyz
## position : 117
## chaineVF : efghijklmnopqrstuvwxyz
## position : 144
## chaineVF : defghijklmnopqrstuvwxyz
## position : 171
## chaineVF : cdefghijklmnopqrstuvwxyz
## position : 198
## chaineVF : bcdefghijklmnopqrstuvwxyz
## position : 225
## chaineVF : abcdefghijklmnopqrstuvwxyz
## position : 252 |
Je soupconne trés fortement le tellg qui vient tout foutre en l'air, car quand je ne l'utilise pas tout ce passe bien, et franchement je vois pas pourquoi l'utilisation de tellg viendrait autant perturbé le getline, je suis perdu ...
Alors si quelqu'un peut m'expliquer clairement d'où vient le problème ca serait sympa, merci ;)