   Variable type converting?
  Hello,I was wondering if in native C++ there are any ways to convert integers to characters or strings?I searched google but all I found was using printf and stuff like that but that would not work in the case of how i'm using the variables, I need an integer varibale's value in a char parameter.Thanks,Progames25   
  Like so:#include <sstream>#include <string>template<class Type>std::string Stringify( const Type& input ){std::stringstream ss;ss << input;return ss.str();} [Edited by - _fastcall on May 13, 2009 2:08:33 AM];  I'm not sure what you mean by "native C++", but there are definitely ways to do it without printf (and it's variants).   ;  what do you mean "native" c++? There's nothing built into the language itself, but there are plenty of options in the standard library. Assuming you want the integer 123 to end up as a string "123", there are several ways. You can use a stringstream, sprintf, boost::lexical_cast or you can roll your own. If you're 100% sure you're working only in ascii, this is pretty trivial, but to be honest it's not really worth it. Just use one of the standard library ways and you'll be sweet.edit: required reading;  Moving to For Beginners.   ;  yes using the function itoa.http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/;Quote:Original post by tnuttyyes using the function itoa.Note though that itoa is a non-standard extension, although widely supported.It also requires that you pass in a buffer that is long enough to contain any possible value.There is little or no reason to use itoa over a stringstream in C++.   ;  If by "native C++" you mean only the core language and without external libraries: Sure there is a way. To just present to you the simplest function, int to character:char itoc (int i) {    if (i<0 || i>9)   throw some_invalid_conversion_exception();    static const char conv [] = {   '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'    };    return conv ;}There is also a version that works without a lookup, but it is not portable C++ and assumes that '0'..'9' are continous in underlying integer value (which is the case with most x86 compilers:char itoc (int i) {    if (i<0 || i>9)   throw some_invalid_conversion_exception();    return i + '0';};  Eurgh.Please, please, please do not use unsafe functions like itoa (buffer overflow exploits). Also, please do not roll your own lexical cast functions unless you know what you're doing. (See boost::lexical_cast - it's more complex than it sounds.)Just use the tools provided to you in the language (stringstreams) or in well-respected libraries (boost::lexical_cast).   ;  Hello,Thanks for all the different options.Ok..i'll try not to use ipoa.Let me check these out...Thanks,progames25   