Casting int to char*

U

urskris123

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 ,
 
A

Alf P. Steinbach

* (e-mail address removed):
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>.
 
U

urskris123

* (e-mail address removed):




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
 
A

Alf P. Steinbach

* (e-mail address removed):
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.
 
G

Gavin Deane

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
 
U

urskris123

* (e-mail address removed):



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?


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
 
J

Jim Langston

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

casting unsigned int to void* 18
casting int to char 11
C++ casting: object type -> char * 2
Casting template argument 3
casting from void* to const char * 3
string type casting to int 6
casting 1
Int to char[4] 43

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top