<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<font style="" face="Times New Roman">Buenos días.</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">He estado ojeando la web y no he sabido encontrar una manera de convertir una variable cualquiera de mi programa a string.</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">Pongamos el ejemplo:</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">- Tengo una variable int, que en un momento determinado tiene un valor. Tengo una libería que guarda datos, pero solo admite strings. Por tanto, he de transformar la variable a string antes.</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">if (myPlayedTimeTotal > myPlayedTimeTotalMax)</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">    {</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">        miniDictionary->setObject(CCString(myPlayedTimeTotal),std::string("timetotal_max"));    // No funciona, "myPlayedTimeTotal" es un integer y el constructor de CCString no lo admite</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">    }</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">CCString pertenece a una librería (cocos2d-x) cuya referencia es:</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><br></font><table class="memberdecls"><tbody><tr class="memitem:a19f899e12cfcebb08c277bbf9c42d0a8"><td class="memItemLeft" align="right" valign="top"><font style="" face="Times New Roman"> </font></td><td class="memItemRight" valign="bottom"><font style="font-size: 10pt;" face="Times New Roman" size="2"><a class="el" href="http://www.cocos2d-x.org/embedded/cocos2d-x/dd/d36/classcocos2d_1_1_c_c_string.html#a19f899e12cfcebb08c277bbf9c42d0a8">CCString</a></font><font style="font-size: 10pt;" face="Times New Roman" size="2"> (const char *str)</font></td></tr>
<tr class="separator:a19f899e12cfcebb08c277bbf9c42d0a8"><td class="memSeparator" colspan="2"><font style="" face="Times New Roman"> </font></td></tr>
<tr class="memitem:ab6a823b3b3902758f6c8e88d94b232e2"><td class="memItemLeft" align="right" valign="top"><font style="" face="Times New Roman"> </font></td><td class="memItemRight" valign="bottom"><font style="font-size: 10pt;" face="Times New Roman" size="2"><a class="el" href="http://www.cocos2d-x.org/embedded/cocos2d-x/dd/d36/classcocos2d_1_1_c_c_string.html#ab6a823b3b3902758f6c8e88d94b232e2">CCString</a></font><font style="font-size: 10pt;" face="Times New Roman" size="2"> (const std::string &str)</font></td></tr>
<tr class="separator:ab6a823b3b3902758f6c8e88d94b232e2"><td class="memSeparator" colspan="2"><font style="" face="Times New Roman"> </font></td></tr>
<tr class="memitem:ab3e8b88f12c897f92c537c2e2f63e1af"><td class="memItemLeft" align="right" valign="top"><font style="" face="Times New Roman"> </font></td><td class="memItemRight" valign="bottom"><font style="font-size: 10pt;" face="Times New Roman" size="2"><a class="el" href="http://www.cocos2d-x.org/embedded/cocos2d-x/dd/d36/classcocos2d_1_1_c_c_string.html#ab3e8b88f12c897f92c537c2e2f63e1af">CCString</a></font><font style="font-size: 10pt;" face="Times New Roman" size="2"> (const </font><font style="font-size: 10pt;" face="Times New Roman" size="2"><a class="el" href="http://www.cocos2d-x.org/embedded/cocos2d-x/dd/d36/classcocos2d_1_1_c_c_string.html">CCString</a></font><font style="font-size: 10pt;" face="Times New Roman" size="2"> &str)</font></td></tr></tbody></table><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman">He encontrado código que lo hace, aunque algo engorroso:</font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><br></font><font style="" face="Times New Roman"><b>#include <sstream></b></font><BR>
<font style="" face="Times New Roman"><b>int i = 5;<br>
std::string s;<br>
std::stringstream out;<br>
out << i;<br>
s = out.str();</b></font><BR><font style="" face="Times New Roman"><br></font><BR><font style="" face="Times New Roman">¿Hay una forma más sencilla de hacerlo sin usar un stringstream?</font><BR><font style="" face="Times New Roman"><br></font><BR><font style="" face="Times New Roman">El problema es que son muchas las variables que tengo que pasar, y quiero que se haga de la manera más sencilla y rápida posible.</font><BR><font style="" face="Times New Roman"><br></font><BR><font style="" face="Times New Roman">Gracias, un saludo.</font><font style="" face="Times New Roman"><br></font><BR><br>                                      </div></body>
</html>