Boucle en c++
Résolu/Fermé
philou
-
21 janv. 2012 à 09:10
KX Messages postés 16755 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 12 février 2025 - 21 janv. 2012 à 18:56
KX Messages postés 16755 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 12 février 2025 - 21 janv. 2012 à 18:56
2 réponses
KX
Messages postés
16755
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
12 février 2025
3 020
21 janv. 2012 à 12:51
21 janv. 2012 à 12:51
Il faut que tu doubles ton slash, parce que \r c'est un retour chariot --> "C:\\resultlot.txt"
Ensuite il serait bon de tester si le fichier a bien été ouvert avec is_open().
Après ton sprintf(b' "%d"' i) est vraiment bizarre... Tu peux utiliser << pour écrire tes données dans le fichier.
Ensuite il serait bon de tester si le fichier a bien été ouvert avec is_open().
Après ton sprintf(b' "%d"' i) est vraiment bizarre... Tu peux utiliser << pour écrire tes données dans le fichier.
#include<iostream> int main (void) { std::ofstream fic("c:\\resultlot.txt", std::ios::out | std::ios::binary); if (!fic.is_open()) { std::cerr << "Fichier non ouvert" << std::endl; return 1; } for (int i=0; i<6; i++) fic << i; fic.close(); return 0; }
je voudrais faire un retour chariot dans l'ecriture
c est à dire
1
2
3
4
5
etc.....
et non pas 1 2 3 4 5......
c est à dire
1
2
3
4
5
etc.....
et non pas 1 2 3 4 5......
KX
Messages postés
16755
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
12 février 2025
3 020
21 janv. 2012 à 18:56
21 janv. 2012 à 18:56
Utilises std::endl
for (int i=0; i<6; i++) fic << i << std::endl;
21 janv. 2012 à 17:19
21 janv. 2012 à 17:23
21 janv. 2012 à 17:25
C:\Dev-Cp||=== Build finished: 1 errors, 0 warnings ===|p\thermlot.cpp|9|error: variable 'std::ofstream fic' has initializer but incomplete type|
21 janv. 2012 à 17:47
ups!!!!!!!!!
21 janv. 2012 à 17:49