473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 12546
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.