Bonjour,
Après avoir écumé les tutos du NET, je cherche une âme charitable que je remercie par avance.
Ca fait 10 jours que j'essaie en vain de faire marcher un couple script (l'un écrit, l'autre lit) avec deux solutions différentes, je suis un peu découragé (10 jours).
voilà les codes :
ecriture :
lecture :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 #include<iostream> #include<fstream> using namespace std; int main() { int INIT = 1; string sn = "0000000000000000"; double focus = 0.00; fstream wf(".dict_interface.bin", ios::out | ios::binary); //wf.seekg(0, ios::beg); if(!wf) { cout << "défaut !" << endl; } else { wf.write ((char *)&INIT, sizeof(int)); wf.write ((char *)&sn, sizeof(64)); wf.write ((char *)&focus, sizeof(double)); } wf.close(); return 0; }
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 #include<iostream> #include<fstream> using namespace std; int main() { int INIT; char sn; double focus; fstream rf(".dict_interface.bin", ios::in | ios::binary); rf.clear(); rf.seekg(0, ios::beg); if(!rf) { cout << "défaut !" << endl; } else { rf.read ((char *)&INIT, sizeof(int)); rf.read ((char *)&sn, sizeof(64)); rf.read ((char *)&focus, sizeof(focus)); } rf.close(); cout << INIT << endl; cout << sn << endl; cout << focus << endl; return 0; }
ecriture1 :
lecture1 :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 #include<iostream> #include<cstdio> using namespace std; int main(void) { FILE * f; int INIT = 1; string sn = "0000000000000000"; double focus = 0.00; f = fopen(".dict_interface.bin", "wb"); if(f==NULL) { cout << "défaut !" << endl; } else { fwrite (&INIT, sizeof(int),1,f); fwrite (&sn, sizeof(string),16,f); fwrite (&focus, sizeof(double),1,f); } return 0; }
Les deux solutions ne marchent pas écriture/lecture tout comme écriture1/lecture1Code:
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 #include<iostream> #include<cstdio> using namespace std; int main(void) { FILE * f; int INIT; string sn; double focus; f = fopen(".dict_interface.bin", "rb"); if(f==NULL) { cout << "défaut !" << endl; } else { fread (&INIT, sizeof(int),1,f); fread (&sn, sizeof(string),16,f); fread (&focus, sizeof(double),1,f); fclose(f); } cout << INIT << endl; cout << sn << endl; cout << focus << endl; return 0; }
Je débute en c++, après avoir appris Python3, et y a environ 35 ans l'assembleur de divers microproce 6500 6800 68000, là je suis chercheur chez Polemploi donc c'est un passe temps mais que je pense utiliser prochaine, encore une fois merci d'avance et de votre générosité.