Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

function to convert int to string

3 views
Skip to first unread message

Daniel

unread,
Jun 9, 2008, 6:29:39 PM6/9/08
to
I can't find the documentation on the function to convert integer to string.
Anyone know it off the top of his / her head?

Daniel


Nathan Mates

unread,
Jun 9, 2008, 6:49:29 PM6/9/08
to
In article <uJusPBoy...@TK2MSFTNGP04.phx.gbl>,

Daniel <Mah...@cableone.net> wrote:
>I can't find the documentation on the function to convert integer to string.
>Anyone know it off the top of his / her head?

What language (C, C++, C#, VB, other) are you using? In C/C++, you
can use sprintf. I'm not a mindreader, so the more information you
provide, you can help others help you.

Nathan Mates

--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein

Ron Francis

unread,
Jun 9, 2008, 7:54:30 PM6/9/08
to

"Daniel" <Mah...@cableone.net> wrote in message
news:uJusPBoy...@TK2MSFTNGP04.phx.gbl...

>I can't find the documentation on the function to convert integer to
>string. Anyone know it off the top of his / her head?
>
> Daniel
>

Assuming C/C++:
As Nathan said, sprintf( ) but to be more safe use sprintf_s( )
You can also look at _itoa_s( )

Regards,
Ron Francis
www.RonaldFrancis.com


David Wilkinson

unread,
Jun 9, 2008, 8:21:27 PM6/9/08
to

Daniel:

and std::ostringstream.

--
David Wilkinson
Visual C++ MVP

Daniel

unread,
Jun 9, 2008, 9:10:34 PM6/9/08
to
I'm in the microsoft.public.vc.language newsgroup. I mean the c/c++
language.


"Nathan Mates" <nat...@visi.com> wrote in message
news:GoednRYIfbfkLtDVnZ2dnUVZ_siknZ2d@visi...

Tom Serface

unread,
Jun 10, 2008, 3:04:46 AM6/10/08
to
If you use CString it's easy with something like:

CString cs;
cs.Format(_T("%d"),nIntVal);

You can also use itoa(), but it's more work.

Tom

"Daniel" <Mah...@cableone.net> wrote in message
news:uJusPBoy...@TK2MSFTNGP04.phx.gbl...

Ulrich Eckhardt

unread,
Jun 10, 2008, 3:54:47 AM6/10/08
to
Daniel wrote:
> I mean the c/c++ language.

Wrong. There is no such language. If you mean C, the answer will be
different than for C++, at least because they use different ways to
represent and handle strings. If you use C#, the answer will differ even
more. Even if you use C++, the answer will be different if you use the MFC
instead of the C++ standardlibrary. Anyway, google for "convert int string
<yourlanguage>" and you will find lots of answers.

Uli

--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Giovanni Dicanio

unread,
Jun 10, 2008, 5:47:07 AM6/10/08
to

"Tom Serface" <tom.n...@camaswood.com> ha scritto nel messaggio
news:D2355C68-374F-4A63...@microsoft.com...

> If you use CString it's easy with something like:
>
> CString cs;
> cs.Format(_T("%d"),nIntVal);
>
> You can also use itoa(), but it's more work.

I agree with Tom.

You may define a function to wrap Tom's code (that is what I use to do):

<code>

// Converts from integer to string
inline CString ToString( int n )
{
CString s;
s.Format( _T("%d"), n );
return s;
}

</code>

And in your code you can just write:

int n;
int m;
...


CString msg;
msg = _T("N = ") + ToString( n );
msg += _T("M = ") + ToString( m );
...

Giovanni

Tom Serface

unread,
Jun 10, 2008, 10:45:19 AM6/10/08
to
Handy how .NET has that built into just about every object type ... :o)

Tom

"Giovanni Dicanio" <giovanni...@invalid.com> wrote in message
news:e$ATf9tyI...@TK2MSFTNGP02.phx.gbl...

Giovanni Dicanio

unread,
Jun 10, 2008, 12:41:47 PM6/10/08
to

"Tom Serface" <tom.n...@camaswood.com> ha scritto nel messaggio
news:E80359F2-25BD-408B...@microsoft.com...

> Handy how .NET has that built into just about every object type ... :o)

Yes Tom.
...But it seems that we in the C++ world like to build things by ourselves
;-)

G


Hendrik Schober

unread,
Jun 12, 2008, 10:41:50 AM6/12/08
to
Daniel schrieb:

> I can't find the documentation on the function to convert integer to string.
> Anyone know it off the top of his / her head?

template< typename T >
inline
std::string convert2str(const T& obj)
{
std::ostringstream oss;
oss << obj;
return oss.str();
}

> Daniel

Schobi

0 new messages