View previous topic :: View next topic |
Author |
Message |
Chaosis13 Master Cheater
Reputation: 0
Joined: 14 Aug 2007 Posts: 372
|
Posted: Tue Nov 25, 2008 10:52 pm Post subject: [VC++] Int to String for Textbox |
|
|
I need to convert a int to a string, so I can have a textbox display it. I have already found out how to convert the textbox's text to an int, i just need to do it in reverse.
Is there something like this:
Code: | this->textBox1->Text = int1.ToString; |
Because it isn't working for me.
|
|
Back to top |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Tue Nov 25, 2008 11:26 pm Post subject: |
|
|
This is in C#, but i'm sure it will give you the basic idea as for IntToStr
http://msdn.microsoft.com/en-us/library/aa664785.aspx
_________________
qwerty147 wrote: |
ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Nov 25, 2008 11:29 pm Post subject: |
|
|
ugh god don't use Manged C++, it's no longer supported.
Use C# instead, and look at the Convert class.
Convert->ToInt32(TextBox1->Text);
Last edited by hcavolsdsadgadsg on Tue Nov 25, 2008 11:32 pm; edited 1 time in total |
|
Back to top |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Tue Nov 25, 2008 11:32 pm Post subject: |
|
|
No longer supported? ?Tahw yas
_________________
qwerty147 wrote: |
ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Tue Nov 25, 2008 11:33 pm Post subject: |
|
|
sprintf(message,"%d",value);
converts int value to string message
_________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Wed Nov 26, 2008 10:21 am Post subject: |
|
|
try itoa
int to asci o0
wtf ppl read more documentation!
or for the opposite
try atoi
ascii to int o0
....grr...
|
|
Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Wed Nov 26, 2008 10:35 am Post subject: |
|
|
Bizarro wrote: | sprintf(message,"%d",value);
converts int value to string message |
First, using "%d" will convert it into a value not a string.
Second, it would only use the int as an ascii of the char.
|
|
Back to top |
|
 |
Chaosis13 Master Cheater
Reputation: 0
Joined: 14 Aug 2007 Posts: 372
|
Posted: Wed Nov 26, 2008 11:57 am Post subject: |
|
|
Code: | int int1 = 20;
char char1[100];
_itoa (int1, char1, 10);
this->textBox1->Text = Convert::ToString(char1); |
That works... And so does this....
Code: | int int1 = 20;
this->textBox1->Text = Convert::ToString(int1); |
Ty. And screw C#, that will never be as good as C++.
|
|
Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Wed Nov 26, 2008 12:10 pm Post subject: |
|
|
Zerith wrote: | Bizarro wrote: | sprintf(message,"%d",value);
converts int value to string message |
First, using "%d" will convert it into a value not a string.
Second, it would only use the int as an ascii of the char. |
You're wrong. Bizarro is right, that code will convert the value of 'value' to a string and put that string into 'message'.
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Nov 26, 2008 12:43 pm Post subject: |
|
|
Chaosis13 wrote: | Code: | int int1 = 20;
char char1[100];
_itoa (int1, char1, 10);
this->textBox1->Text = Convert::ToString(char1); |
That works... And so does this....
Code: | int int1 = 20;
this->textBox1->Text = Convert::ToString(int1); |
Ty. And screw C#, that will never be as good as C++. |
Except you're not using C++, you're using the managed version. Yes, it runs off the .NET framework, and no, there is no support for managed C++ any more. Microsoft doesn't support the product.
It's outdated, shitty, and completely outclassed by C# in any way you slice it.
|
|
Back to top |
|
 |
Chaosis13 Master Cheater
Reputation: 0
Joined: 14 Aug 2007 Posts: 372
|
Posted: Wed Nov 26, 2008 12:47 pm Post subject: |
|
|
I don't care, I normally don't use VC++, I prefer Dev-C++. I just wanted to spend less time programming the interface. And I will never learn C#.
|
|
Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Wed Nov 26, 2008 1:03 pm Post subject: |
|
|
tombana wrote: | Zerith wrote: | Bizarro wrote: | sprintf(message,"%d",value);
converts int value to string message |
First, using "%d" will convert it into a value not a string.
Second, it would only use the int as an ascii of the char. |
You're wrong. Bizarro is right, that code will convert the value of 'value' to a string and put that string into 'message'. |
Definition of "%d" by MSDN:
MSDN wrote: |
d Signed decimal integer.
|
I suppose MSDN is wrong then?
|
|
Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Wed Nov 26, 2008 1:18 pm Post subject: |
|
|
Zerith wrote: | tombana wrote: | Zerith wrote: | Bizarro wrote: | sprintf(message,"%d",value);
converts int value to string message |
First, using "%d" will convert it into a value not a string.
Second, it would only use the int as an ascii of the char. |
You're wrong. Bizarro is right, that code will convert the value of 'value' to a string and put that string into 'message'. |
Definition of "%d" by MSDN:
MSDN wrote: |
d Signed decimal integer.
|
I suppose MSDN is wrong then? |
Definition of "sprintf" by MSDN:
MSDN wrote: |
sprintf Write formatted data to a string.
|
I suppose MSDN is wrong then?²
_________________
Gone |
|
Back to top |
|
 |
ElJEffro Grandmaster Cheater Supreme
Reputation: 0
Joined: 15 Apr 2007 Posts: 1881 Location: La Tierra
|
Posted: Wed Nov 26, 2008 1:29 pm Post subject: |
|
|
yeah, and
sprintf(string1, "%X", int1); will format it in hexadecimal number style too if you need that (capital X for format like 0xF33BA3, lower case x for format like 0xf33ba3). You can pad it left as well with it as well "%04X" or %0<number of characters long you want the number to be>< whatever format you are using >
int int1 = 40;
char intAsString[4];
sprintf(intAsString, "%d", int1); //will get you a string "40"
|
|
Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Wed Nov 26, 2008 1:38 pm Post subject: |
|
|
ElJEffro wrote: | yeah, and
sprintf(string1, "%X", int1); will format it in hexadecimal number style too if you need that (capital X for format like 0xF33BA3, lower case x for format like 0xf33ba3). You can pad it left as well with it as well "%04X" or %0<number of characters long you want the number to be>< whatever format you are using >
int int1 = 40;
char intAsString[4];
sprintf(intAsString, "%d", int1); //will get you a string "40" |
I was just saing to Zerith that %d is for decimal numbers but "sprintf" copies it to an string.
_________________
Gone |
|
Back to top |
|
 |
|