#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <ostream>
using namespace std;
const int MAXNAMESIZE=3;
int main(int nNumerofArgs, char* pszArgs[])
{
int chiffre_decimal;
cout <<"Entrer un chiffre decimal a convertir en hexadecimal: ";
cin >> chiffre_decimal;
int divise;
divise = chiffre_decimal/16;
cout <<chiffre_decimal<<"/16 = " << divise <<" ("<<divise<<" est la premiere valeur)";
unsigned int produit;
produit = divise*16;
cout <<"\n"<<divise<<"*16 = " << produit;
unsigned int difference;
difference = chiffre_decimal - produit;
cout <<"\n"<<chiffre_decimal<<" - "<<produit<<" ("<<produit<<" est la seconde valeur)";
if (difference==10)
cout<<"\n"<<chiffre_decimal<<" est"<<" 0x"<<(cout<<divise)<<"A"<<" en hexadecimal\n";
if( difference== 11)
cout<<"\n"<<chiffre_decimal<<" est"<<" 0x"<<divise<<"B"<<" en hexadecimal\n";
if( difference== 12)
cout<<"\n"<<chiffre_decimal<<" est"<<" 0x"<<divise<<"C"<<" en hexadecimal\n";
if( difference== 13)
cout<<"\n"<<chiffre_decimal<<" est"<<" 0x"<<divise<<"D"<<" en hexadecimal\n";
if( difference== 14)
cout<<"\n"<<chiffre_decimal<<" est"<<" 0x"<<divise<<"E"<<" en hexadecimal\n";
if( difference== 15)
cout<<"\n"<<chiffre_decimal<<" est"<<" 0x"<<divise<<"F"<<" en hexadecimal\n";
if(difference!=10 && difference!=11 && difference!=12 && difference!=13 && difference!=14 && difference!=15)
cout<<"\n"<<chiffre_decimal<<" est"<<" Ox" <<divise<<difference<<" en hexadecimal\n" ;
system("PAUSE");
return 0;
}
Bonjour a tous,
Voici mon code.
Je voudrais sauvegarder le contenue de la variable difference dans un fichier texte (.txt) nommé operation.txt
Seulement je ne sais pas trop comment faire car j'ai essayé avec un ofstream et je ne suis pas arrivé.
Merci pour votre aide