Discussion: Re: integer to char*
Afficher un message
Vieux 15/01/2008, 20h35   #1
Tristan Wibberley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: integer to char*


On Tue, 2008-01-15 at 11:15 -0800, 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...


You don't cast your int, you convert it.

#include <sstream>
#include <ostream>

....

std:stringstream s;
s << my_int;
textout_ex(..., s.str().c_str(), ...);

or, if the allegro textout_ex function barfs due to something about
"const", try:

#include <vector>
#include <sstream>
#include <ostream>

....

std:stringstream s;
s << my_int;
std::vector<char> v(s.str().begin(), s.str().end());
v.push_back('\0');
textout_ex(..., &v[0], ...); // &v[0] is okay because v.size() >= 1

--
Tristan Wibberley

Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.

  Réponse avec citation
 
Page generated in 0,04452 seconds with 9 queries