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

Casting int to char*

P: n/a
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,

kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,

Mar 24 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
* ur********@gmail.com:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,

kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.

In C++, use std::string.

See FAQ item 39.1, currently available at <url:
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 24 '07 #2

P: n/a
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,

You mean you want to convert an integer to a decimal string representation.

In C++, use std::string.

See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Thank you but i need that i should get the result in char* format .I
need to give the labels like i specified .Am new to the groups .Sorry

Mar 24 '07 #3

P: n/a
* ur********@gmail.com:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
>* urskris...@gmail.com:
>>I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.

In C++, use std::string.

See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.

Thank you but i need that i should get the result in char* format .
Most probably you don't.

What is it that you're trying to achieve?

Don't tell about how you're trying to achieve that, the char*-based
scheme you have in mind, don't tell about that but /what/ is the effect
you want?

>I need to give the labels like i specified .Am new to the groups .Sorry
Yes, you should not quote signatures. I've corrected that in this
follow-up.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 24 '07 #4

P: n/a
On 24 Mar, 08:35, urskris...@gmail.com wrote:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.
In C++, use std::string.
See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.

Thank you but i need that i should get the result in char* format .I
need to give the labels like i specified .Am new to the groups .Sorry
Please don't quote signatures. Thank you.

If you really need to end up with a C-style string, after you've
created a std::string following the FAQ Alf posted, use the c_str()
member function of std::string. Bear in mind that you shouldn't alter
the string via the raw char* and you shouldn't use the raw char* if
you make any subsequent changes to the std::string. But neither of
those should matter if you do all the assembling and altering in the
std::string first.

Why is it you need a char*? Are you interfacing with some third party
function that takes a char*? Or are you doing an exercise where the
requirement is to use C-style strings?

Gavin Deane

Mar 24 '07 #5

P: n/a
On Mar 24, 1:48 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
>I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.
In C++, use std::string.
See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.
Thank you but i need that i should get the result in char* format .

Most probably you don't.

What is it that you're trying to achieve?

Don't tell about how you're trying to achieve that, the char*-based
scheme you have in mind, don't tell about that but /what/ is the effect
you want?
I need to give the labels like i specified .Am new to the groups .Sorry

Yes, you should not quote signatures. I've corrected that in this
follow-up.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
I want to append a number for labels in the loop .i achieved it thank
you .I did by using istring lb1="kris" and then lb1+=i(0,1,2,...in for
loop ) and then converting it into char* by c_str().

Thank you

Mar 24 '07 #6

P: n/a
<ur********@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
On Mar 24, 1:48 pm, "Alf P. Steinbach" <a...@start.nowrote:
>* urskris...@gmail.com:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
>>I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string
representation.
>In C++, use std::string.
>See FAQ item 39.1, currently available at
<url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.
Thank you but i need that i should get the result in char* format .

Most probably you don't.

What is it that you're trying to achieve?

Don't tell about how you're trying to achieve that, the char*-based
scheme you have in mind, don't tell about that but /what/ is the effect
you want?
>I need to give the labels like i specified .Am new to the groups .Sorry

Yes, you should not quote signatures. I've corrected that in this
follow-up.

I want to append a number for labels in the loop .i achieved it thank
you .I did by using istring lb1="kris" and then lb1+=i(0,1,2,...in for
loop ) and then converting it into char* by c_str().
Wow, and you have gmail?

Mar 24 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.