Bonsoir,
J'aimerai votre aide pour ce code qui me permet de lire un fichier et de l'afficher octet par octet, mais que je n'arrive pas modifier pour lire par exemple 8 octets par 8 octets.
Code pour 1 octet (fonctionne) :
Tentative pour 8 octets :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include <iostream> #include <fstream> using namespace std; int main() { string fichier = "mon fichier"; ifstream fluxFichier(fichier.c_str(),ios::binary); fluxFichier.seekg(0,ios::beg); char caractere ='\n'; int i = -1; do { cout << caractere; fluxFichier.read(&caractere,1); i++; } while (!fluxFichier.eof()); cout << endl << endl << i << "octet(s)"; return 0; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <iostream> #include <fstream> using namespace std; int main() { string fichier = "mon fichier"; ifstream fluxFichier(fichier.c_str(),ios::binary); fluxFichier.seekg(0,ios::beg); char caracteres[8]; int i = 0; do { cout << caracteres; fluxFichier.read(&caracteres,8); i++; } while (!fluxFichier.eof()); cout << endl << endl << i << "itération(s)"; return 0; }et je ne saisis pas le problème de type de variable qui bloque... il faut bien un tableau de char si on lit plusieurs octets ?17 error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::read(char (*)[8], int)’
/usr/include/c++/4.4/istream 464 note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::read(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]
j'ai aussi trouvé ce code qui ne fonctionne pas... http://www.developpez.net/forums/d95...t/#post5392048
Partager