|
-
April 14th, 2004, 09:25 PM
#1
newbie - how do i set a int var to a char
Hi,
Im new to c++ and semi experienced at vb.
I need to know how to convert a integer type variable for example to a string type (char?) variable Is there some keyword or easy way to do this that im missing?
My question is, how do I do this in c++?:
dim newVar as integer = cint(stringVariable)
or
dim newVar as String = cStr(numberVariable)
I need to set a integer variable to a string see? Let me know, thanks.
-JBD
-
April 14th, 2004, 09:31 PM
#2
This is really easy.
int mynumber = 5;
char buf[501]; CString str;
sprintf(buf, "%i", mynumber); str = buf;
So now it's a CString.
I hope this helps.
-
April 14th, 2004, 09:35 PM
#3
Have a look in MSDN at function _itoa:
_itoa
Convert an integer to a string.
char *_itoa( int value, char *string, int radix );
Alternatively, if you are using CString you can use the Format member function:
eg:
Code:
CString str;
int i = 1;
str.Format("%d", i);
-
April 15th, 2004, 12:28 AM
#4
Take a look at the following FAQ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|