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
| // ouverture du fichier
ifstream fichierInput( "../../data/Balise.xyzb" );
// verification
if (!fichierInput)
cout << "\nt'es dans le caca avec ton fichier\n";
else
{
// on tente un truc rapide -> on met tout dans un buffer
stringstream buff;
buff << fichierInput.rdbuf();
//cout << "Taille du buffer : " << buff.str().size() << '\n';
// plus besoin du fichier donc
fichierInput.close();
// on fait la petite feinte pour choper largeur, longueur et resolution
//findInfo(buff);
string line;
float x1, y1, z1, x2, y2, z2, x3, y3, z3;
//lecture de la premiere ligne
getline(buff, line);
istringstream firstLine(line);
firstLine >> x1 >> y1 >> z1;
cout << "\n on a " << x1 << " " << y1 << " " << z1 << "\n";
//lecture de la deuxieme ligne
getline(buff, line);
istringstream secondLine(line);
secondLine >> x2 >> y2 >> z2;
cout << "\n on a " << x2 << " " << y2 << " " << z2 << "\n";
//positionnnement a la fin du fichier
buff.seekg(0, ios::end);
getline(buff, line);
istringstream lastLine(line);
lastLine >> x3 >> y3 >> z3;
cout << "\n on a " << x3 << " " << y3 << " " << z3 << "\n";
// du coup faut se replacer au debut
buff.seekg(0, ios::beg);
// cette boucle s'arrete des qu'une erreur de lecture survient
while (getline(buff, line))
{
// on enregistre ligne par ligne mais evidemment faut sauter le "BCN,"
istringstream iss( line );
iss >> tmpx >> tmpy >> tmpz;
// comment choper que l'entier apres le "," ???
getline (iss, bcn, ',');
getline (iss, bcn, ',');
istringstream iss2( bcn );
iss2 >> tmpb;
cout << "\n on a enregistre " << tmpx << " " << tmpy << " " << tmpz << " " << tmpb << "\n";
}
// on supprime le buffer
buff.flush();
} |
Partager