By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

integer to string conversion

P: n/a
sam
Hi,

Does STL has Integer class?
I want to convert an integer to string.
Of course I can use sprintfs C API, but I m wondering whether STL has
Integer class to be utilsed.

Thanks
Sam.
Jul 23 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
sam <sam++@--.com> writes:
Hi, I want to convert an integer to string.

See the FAQ.
Jul 23 '05 #2

P: n/a

"sam" <sam++@--.com> wrote in message news:d4***********@news.hgc.com.hk...
| Hi,
|
| Does STL has Integer class?
| I want to convert an integer to string.
| Of course I can use sprintfs C API, but I m wondering whether STL has
| Integer class to be utilsed.

There is no 'Integer' class in C++, however you can write
one yourself.

C++ has std::stringstream(s) to do the job for you.

Look up the many examples posted on usenet in the past.
You'll want to use an 'std::ostringstream' object.

Cheers,
Chris Val
Jul 23 '05 #3

P: n/a
sam wrote:
Hi,

Does STL has Integer class?
No. There is no need for one.
I want to convert an integer to string.


Use std::istringstream for that.

std::istringstream stream;
int i = 4;
stream << i;
std::string s = stream.str();

Jul 23 '05 #4

P: n/a

"sam" <sam++@--.com> wrote in message news:d4***********@news.hgc.com.hk...
Hi,

Does STL has Integer class?
No.
I want to convert an integer to string.
Of course I can use sprintfs C API, but I m wondering whether STL has
Integer class to be utilsed.
See:
http://www.parashift.com/c++-faq-lit....html#faq-39.1

Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>


Thanks
Sam.

Jul 23 '05 #5

P: n/a
Have you tried the itoa() library function? It return char * to string
for the corresponding integer. It's arguments include destination
string, number to be converted, and base of the number. (I don't
remember the order).

Jul 23 '05 #6

P: n/a
Angad wrote:
Have you tried the itoa() library function? It return char * to string
for the corresponding integer. It's arguments include destination
string, number to be converted, and base of the number. (I don't
remember the order).

There *is* no such function in standard C++.

--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #7

P: n/a
Angad wrote:
Have you tried the itoa() library function? It return char * to string
for the corresponding integer. It's arguments include destination
string, number to be converted, and base of the number. (I don't
remember the order).

There is no such function in the standard C or C++ library.
Jul 23 '05 #8

P: n/a
I don't know that, but I remember using it while programming in Visual
C++

Jul 23 '05 #9

P: n/a
Check out this link
http://www.mkssoftware.com/docs/man3/itoa.3.asp

Jul 23 '05 #10

P: n/a
Hi,

take a look at boost::lexical_cast. It wraps the entire stringstream
idea and as far as I know it's header-only, so no need to build the lib.

Jan Eickmann

sam wrote:
Hi,

Does STL has Integer class?
I want to convert an integer to string.
Of course I can use sprintfs C API, but I m wondering whether STL has
Integer class to be utilsed.

Thanks
Sam.

Jul 23 '05 #11

P: n/a
Angad wrote:

Check out this link
http://www.mkssoftware.com/docs/man3/itoa.3.asp


It doesn't matter that on some systems there is a function
called 'itoa'.

It is not available on all systems. This group is about *standard*
C++. That is: The language as defined by the corresponding ISO document.
And in those document no function 'itoa' is mentioned.

When working in these group, please restrict yourself to recommend
only things that are described in the language standard.
Thank you.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #12

P: n/a
Ok guys, my mistake. It won't happen again. You see, I'm an undergrad,
not fully aware of *standard* c++. So pardon me.
Could anyone give a link to the ISO document defining standard C++?

Jul 23 '05 #13

P: n/a
On 19 Apr 2005 07:43:52 -0700, Angad
<ka*********@gmail.com> wrote:
Ok guys, my mistake. It won't happen again. You see, I'm an undergrad,
not fully aware of *standard* c++. So pardon me.
You might ask your instructors why they aren't teaching standard C++,
and also ask in your library (assuming universities still have libraries
these days, they did when I was an undergrad 30 years ago).
Could anyone give a link to the ISO document defining standard C++?


Go to http://webstore.ansi.org/ansidocstore/ and search for 14882 (the
ISO/IEC number for the document). They have it for download as a PDF
for US$18 (the usage requirements are very strict, though).

Stroustrup's "The C++ Standard: Incorporating Technical Corrigendum No. 1"
is available from Amazon.com price $56.11 and contains the standard up
to 2003 in a hardcover edition published by Wiley (normal price $70).
ISBN 0470846747, if your library wants to order it...

Chris C
Jul 23 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.