casting int to string

Started by
13 comments, last by Pilatus 20 years, 9 months ago
Normally i use borland c++ builder and there i use the IntToStr() function But atm i''m using visual c++, what function do i use here to get this done?
Advertisement
sprintf(string, "%d", integerval);
char *itoa(int);
our new version has many new and good features. sadly, the good ones are not new and the new ones are not good
Try _itoa( int, char *, int ), I''m not sure what the underscore is all about, but it should work.

Kory
"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein
If you are using C++:

#include <sstream> // for std::stringstream (and std::istringstream, etc.)

int someNumber = ...;

std::stringstream ss;
ss << someNumber;
std::string strNumber;
ss >> strNumber;


[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
itoa(int ,char*,10)
works fine
It doesn''t need an underscore.
Thx all for your help
quote:Original post by Pilatus
itoa(int ,char*,10)
works fine

This question gets asked every week - you should use the search facility to find previous answers. For the record, you should avoid itoa(), which is not a Standard C or C++ function. sprintf and stringstream are.
Nah forget the search feature...It was a simple question and easy for us to answer.

If the question was DX VS OPENGL -> Use the search.
-------------Ban KalvinB !
Although this question has been answered, read Bjarne Stroustrup (creator of C++, if you didn''t already know)''s website. He has style & technique FAQ, as well as a Technical FAQ.

Stroustrup''s Homepage (one ugly dude)

Style and Technique FAQ (answers integer to string question)

General FAQ

quote:Original post by granat
Nah forget the search feature...It was a simple question and easy for us to answer.

Even more shameful then that three people managed to recommend a non-standard function. We don't need that sort of misinformation on the boards. Last time I looked, the forum name was `For Beginners' not `By Beginners'.

[edited by - SabreMan on July 3, 2003 11:49:46 AM]

This topic is closed to new replies.

Advertisement