integer to string

J

james

_itoa() is a easiest function,format is as below: you have to include
<stdlib.h>
char *_itoa( int value, char *string, int radix );

char *_i64toa( __int64 value, char *string, int radix );

char * _ui64toa( unsigned _int64 value, char *string, int radix );

wchar_t * _itow( int value, wchar_t *string, int radix );

wchar_t * _i64tow( __int64 value, wchar_t *string, int radix );

wchar_t * _ui64tow( unsigned __int64 value, wchar_t *string, int radix );
 
A

AC 74

I read from a command line using g++. I changed the argv to integers
using atoi() in order to add the numbers. Now I need to change them
from int to string and itoa is not supported. Can somebody please
help me to change these integers back to strings? Thanks.
 
M

Mike Wahler

AC 74 said:
I read from a command line using g++. I changed the argv to integers
using atoi() in order to add the numbers. Now I need to change them
from int to string and itoa is not supported. Can somebody please
help me to change these integers back to strings? Thanks.

#include <iostream>
#include <sstream>
#include <string>

int main()
{
int i(42);
std::eek:stringstream oss;
oss << i;
std::string s(oss.str());
std::cout << s << '\n'; // prints 42
return 0;
}

-Mike
 
P

Peter van Merkerk

james said:
_itoa() is a easiest function,format is as below: you have to include
<stdlib.h>
char *_itoa( int value, char *string, int radix );

char *_i64toa( __int64 value, char *string, int radix );

char * _ui64toa( unsigned _int64 value, char *string, int radix );

wchar_t * _itow( int value, wchar_t *string, int radix );

wchar_t * _i64tow( __int64 value, wchar_t *string, int radix );

wchar_t * _ui64tow( unsigned __int64 value, wchar_t *string, int radix );

This is not a standard function (the leading underscore is a hint that it
is non-standard). Even though the library that came with your compiler has
this function, it is not defined in the C++ standard. Other implementations
of the standard library may or may not support this function.
 
E

Evan Carew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

AC,

try the Boost lib's safe cast operator:

http://www.boost.org/libs/conversion/index.html

AC said:
I read from a command line using g++. I changed the argv to integers
using atoi() in order to add the numbers. Now I need to change them
from int to string and itoa is not supported. Can somebody please
help me to change these integers back to strings? Thanks.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFAKpueoo/Prlj9GScRAmd0AJ9bvStPa7OsTPzsPk9tt9li8nylgACfVEWD
q0Mu/Ov7vN2s5u5PVj6wpY8=
=9pom
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top