Connecting Tech Pros Worldwide Help | Site Map

Casting int to char*

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 24th, 2007, 08:25 AM
urskris123@gmail.com
Guest
 
Posts: n/a
Default Casting int to char*

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 ,


  #2  
Old March 24th, 2007, 08:25 AM
Alf P. Steinbach
Guest
 
Posts: n/a
Default Re: Casting int to char*

* urskris123@gmail.com:
Quote:
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?
  #3  
Old March 24th, 2007, 08:45 AM
urskris123@gmail.com
Guest
 
Posts: n/a
Default Re: Casting int to char*

On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
Quote:
* urskris...@gmail.com:
>
Quote:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
>
Quote:
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
>
Quote:
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

  #4  
Old March 24th, 2007, 08:55 AM
Alf P. Steinbach
Guest
 
Posts: n/a
Default Re: Casting int to char*

* urskris123@gmail.com:
Quote:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
Quote:
>* urskris...@gmail.com:
>>
Quote:
>>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?

Quote:
>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?
  #5  
Old March 24th, 2007, 08:55 AM
Gavin Deane
Guest
 
Posts: n/a
Default Re: Casting int to char*

On 24 Mar, 08:35, urskris...@gmail.com wrote:
Quote:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
Quote:
* urskris...@gmail.com:
>
Quote:
Quote:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
>
Quote:
Quote:
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
>
Quote:
Quote:
even the string "kris" should be a char* .please help me ,
>
Quote:
You mean you want to convert an integer to a decimal string representation.
>
Quote:
In C++, use std::string.
>
Quote:
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

  #6  
Old March 24th, 2007, 08:55 AM
urskris123@gmail.com
Guest
 
Posts: n/a
Default Re: Casting int to char*

On Mar 24, 1:48 pm, "Alf P. Steinbach" <a...@start.nowrote:
Quote:
* urskris...@gmail.com:
>
Quote:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
Quote:
* urskris...@gmail.com:
>
Quote:
Quote:
>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.
>
Quote:
Quote:
In C++, use std::string.
>
Quote:
Quote:
See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.
>
Quote:
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?
>
Quote:
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

  #7  
Old March 24th, 2007, 09:15 AM
Jim Langston
Guest
 
Posts: n/a
Default Re: Casting int to char*

<urskris123@gmail.comwrote in message
news:1174726404.152791.292090@y66g2000hsf.googlegr oups.com...
Quote:
On Mar 24, 1:48 pm, "Alf P. Steinbach" <a...@start.nowrote:
Quote:
>* urskris...@gmail.com:
>>
Quote:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
>* urskris...@gmail.com:
>>
Quote:
>>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.
>>
Quote:
>In C++, use std::string.
>>
Quote:
>See FAQ item 39.1, currently available at
><url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.
>>
Quote:
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?
>>
Quote:
>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?



 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.