472,785 Members | 1,224 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,785 software developers and data experts.

integer to string conversion

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
13 12520
sam <sam++@--.com> writes:
Hi, I want to convert an integer to string.

See the FAQ.
Jul 23 '05 #2

"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
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

"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
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
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
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
I don't know that, but I remember using it while programming in Visual
C++

Jul 23 '05 #9
Check out this link
http://www.mkssoftware.com/docs/man3/itoa.3.asp

Jul 23 '05 #10
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sashi | last post by:
Two questions: (1) I can pull the text of an XML element as a string just fine using code as such: strSomeString = myXmlDoc.SelectSingleNode("/Element1/Element2/Element3",...
8
by: Brent Lievers | last post by:
Greetings, I have a question about parsing a fixed-width integer from a string. Lines of data are being read from a file having a very strict column-delimited format. In my example below,...
15
by: Teresa | last post by:
1) Should I use Integer.Parse to convert a string into an integer in .NET now? CType(sUserID, Integer) OR Integer.Parse(sUserID) 2) And is it better to use the string class to trim, get length,...
5
by: Barry | last post by:
Hello, In VS2003, I tried using an enum and setting it into a field in a datarow. It seems as if the datatype of the field in the row determined what went into the field. If the datatype was...
11
by: nephish | last post by:
Hello there, i need a way to check to see if a certain value can be an integer. I have looked at is int(), but what is comming out is a string that may be an integer. i mean, it will be formatted...
1
by: charles_gero | last post by:
Hi all, I had a question about the topics in the subject and posted to comp.std.c, but feel it may also be appropriate here. Please excuse this crosspost if it is in bad form. I have a...
10
by: Dave griffiths | last post by:
Hi all Using VB2005 on Vista with a Norwegian locale setup. The test program has 3 textboxes the sum held in txt3. Using the code below, txt2 conversion causes an error when it is left empty....
7
by: Spoon | last post by:
Hello everyone, In my code, I use uint16_t (exactly 16-bit-wide unsigned integer type) and I need to print their value in base 10. ...
5
by: pradeep | last post by:
Hello friends: I know some people here don't like to answer C++ questions, but I believe this is really about the underlying C code. Anyway I have posted as well to the other group someone...
0
by: Jim Langston | last post by:
pradeep wrote: Not big enough by far and disappears once IntToString finishes. No reason to have to do this. sprintf( buf, "%d", i ); would also work, although there are hte other...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.