|
-
June 18th, 1999, 10:13 AM
#1
[RESOLVED] Converting DWORD to CString
I have a DWORD variable and want to convert to a CString.
Likewise, I would like to convert a CString to a DWORD.
I know how to do it for other variables using functions like
[code]
number = atoi(str); //string to number
str.Format("%d", number); //number to string
[/ccode]
I would appreciate any suggestions and example code.
-
June 18th, 1999, 11:06 AM
#2
Re: Converting DWORD to CString
Try this.
CString MyString;
DWORD SomeNum;
MyString.Format ("%d", SomeNum);
Lee
-
June 18th, 1999, 11:15 AM
#3
Re: Converting DWORD to CString
surely %d is a normal interger, not a DWORD?
And what about string to DWORD?
-
June 18th, 1999, 11:22 AM
#4
Re: Converting DWORD to CString
Sorry, you should use "%u" instead of "%d" since "%u" is for unsigned ints (which is a DWORD). As far as converting from DWORD to string, I do not know of any unsigned int versions of atoi().
Lee
-
June 18th, 1999, 11:33 AM
#5
Re: Converting DWORD to CString
Yes - %u
And I thought about it - I could use sscanf to convert from string to DWORD:
[code]
DWORD var;
CString MyStr = "1234";
sscanf(MyStr, "%u", &var);
[/ccode]
I think that would work ok.
-
June 18th, 1999, 11:41 AM
#6
Re: Converting DWORD to CString
Actually, there is a function called strtoul, which converts strings to unsigned longs.
unsigned long strtoul( const char *nptr, char **endptr, int base );
Lee
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
|