C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[debutant] formatage suite

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Bruno Causse
Guest





PostPosted: Wed Jun 22, 2005 9:03 pm    Post subject: [debutant] formatage suite Reply with quote



bonsoir, comment formater un nombre hex avec sont prefixe (showbase) en
largeur (setw) constante avec les zeros (si necessaire).

ex 0x0008759ABF0125BC

merci.

--
Bruno Causse
http://perso.wanadoo.fr/othello
Back to top
Richard Delorme
Guest





PostPosted: Wed Jun 22, 2005 10:04 pm    Post subject: Re: [debutant] formatage suite Reply with quote



Bruno Causse a écrit :
Quote:
bonsoir, comment formater un nombre hex avec sont prefixe (showbase) en
largeur (setw) constante avec les zeros (si necessaire).

ex 0x0008759ABF0125BC

Sans utiliser showbase...

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
unsigned long long n = 0x0008759ABF0125BCLL;
cout << "0x" << hex << setw(16) << setfill('0') << n << endl;
return 0;
}


--
Richard

Back to top
Bruno CAUSSE
Guest





PostPosted: Thu Jun 23, 2005 7:30 am    Post subject: Re : [debutant] formatage suite Reply with quote



dans l'article 42b9e07e$0$309$7a628cd7 (AT) news (DOT) club-internet.fr, Richard
Delorme à [email]abulmo (AT) nospam (DOT) fr[/email] a écrit le 23/06/05 0:04 :

Quote:
Bruno Causse a écrit :
bonsoir, comment formater un nombre hex avec sont prefixe (showbase) en
largeur (setw) constante avec les zeros (si necessaire).

ex 0x0008759ABF0125BC

Sans utiliser showbase...

Oui, ca je sais faire :-)


Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Thu Jun 23, 2005 9:29 am    Post subject: Re: formatage suite Reply with quote

Bruno Causse wrote:
Quote:
comment formater un nombre hex avec sont prefixe (showbase) en
largeur (setw) constante avec les zeros (si necessaire).

ex 0x0008759ABF0125BC

std::cout << std::setfill( '0' )
<< std::hex
<< std::showbase
<< std::internal
<< std::setw( 16 )
<< i ;

La clé, c'est qu'il faut utilise la justification « internal »,
exactement comme quand on précise un fill de '0' avec une valeur
signée.

Du constructeur de mon manipulateur Gabi::HexFmt :

myFlags &= ~ std::ios::basefield ;
myFlags |= std::ios::hex ;
if ( isdigit( static_cast< unsigned char >( fill ) )
&& (myFlags & std::ios::adjustfield) == 0 ) {
myFlags |= std::ios::internal ;
}

Mais du code semblable se trouve dans les constructeurs de tous
mes manipulateurs.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


Back to top
Bruno Causse
Guest





PostPosted: Thu Jun 23, 2005 7:45 pm    Post subject: Re: formatage suite Reply with quote

<kanze (AT) gabi-soft (DOT) fr> wrote:

Quote:
std::cout << std::setfill( '0' )
std::hex
std::showbase
std::internal
std::setw( 16 )

18 0x compte pour 2 digits

Quote:
i ;

La clé, c'est qu'il faut utilise la justification « internal »,
exactement comme quand on précise un fill de '0' avec une valeur
signée.

merci.

remarque sans importance dans le cas ou i = 0, 0x est omis curieux.
--
Bruno Causse
http://perso.wanadoo.fr/othello

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.