PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > integer to char*
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
integer to char*

Réponse
 
LinkBack Outils de la discussion
Vieux 15/01/2008, 19h15   #1
rob.ahlberg@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut integer to char*

I got an integer what I trying to use with allegro function
textout_ex() but it wants an char[]/char* as arg... And I really don't
know how to cast it to one...
  Réponse avec citation
Vieux 15/01/2008, 19h29   #2
moschops
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: integer to char*

rob.ahlberg@gmail.com wrote:
> I got an integer what I trying to use with allegro function
> textout_ex() but it wants an char[]/char* as arg... And I really don't
> know how to cast it to one...


Why feed an int to a function requiring a char*? Do you really want to
pass an integer, or have you confused a character representing a number
with the number itself?

For example, int a = 7 and char a = '7' are very different objects.
There is a difference between the number seven and the character '7'.

I suggest you do not cast an integer to a char*; instead use the integer
to create a char* that is the character representing that number. Look
up ASCII on wikipedia and you'll see the standard numerical
representations for each standard ASCII character. You'll soon see the
link between a number and the numerical code that indicates the
character representing that number in the ASCII character set.

'Chops

  Réponse avec citation
Vieux 15/01/2008, 19h30   #3
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: integer to char*

rob.ahlberg@gmail.com wrote:
> I got an integer what I trying to use with allegro function
> textout_ex() but it wants an char[]/char* as arg... And I really don't
> know how to cast it to one...


Uh... The only "cast" I can think of is the 'lexical_cast' from 'Boost'
library. Otherwise, you probably want to convert the integer into its
external representation. See 'sprintf' or 'std:stringstream', etc.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  Réponse avec citation
Vieux 15/01/2008, 19h34   #4
tragomaskhalos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: integer to char*

On 15 Jan, 19:29, moschops <mosc...@madasafish.com> wrote:
> rob.ahlb...@gmail.com wrote:
> > I got an integer what I trying to use with allegro function
> > textout_ex() but it wants an char[]/char* as arg... And I really don't
> > know how to cast it to one...

>
> Why feed an int to a function requiring a char*? Do you really want to
> pass an integer, or have you confused a character representing a number
> with the number itself?
>
> For example, int a = 7 and char a = '7' are very different objects.
> There is a difference between the number seven and the character '7'.
>
> I suggest you do not cast an integer to a char*; instead use the integer
> to create a char* that is the character representing that number. Look
> up ASCII on wikipedia and you'll see the standard numerical
> representations for each standard ASCII character. You'll soon see the
> link between a number and the numerical code that indicates the
> character representing that number in the ASCII character set.
>
> 'Chops


Based on the name of the function, I think the OP just needs
an integer-to-string conversion.
Two steps:
1. See http://www.parashift.com/c++-faq-lit....html#faq-39.1
to see how to convert an int to a std::string (the FAQ is for doubles,
but
you can adapt it easily to int, and I see no need for the exception
stuff
in that case).
2. textout_ex(std_string_from_step_1.c_str());

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h15.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11504 seconds with 12 queries