Solved

Cast from DWORD to string

Posted on 2000-05-15
4
2,927 Views
Last Modified: 2012-06-27
A beginer questin:
How do I cast a from Dword to string ?
Thank's

AA
0
Comment
Question by:arnonayal
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
tvanceplus earned 50 total points
ID: 2811983
Here is some code that could do it.

/*code  myword already contains desired value*/

__int64 temp;
temp=myword;
char buffer[50];

_i64toa(temp,buffer,10);

CString str=buffer;

/*end code*/

Good Luck!
0
 
LVL 22

Expert Comment

by:nietod
ID: 2812095
A DWORD is 32 bits, not 64, so you could use _itoa(), not __i64toa().  (Although i64toa() would work, its overkill.).

However this is not a portable solution--if that matters.  A portable solution would be to use sprintf() or to output the information to a string stream object and then obtain the string from the string stream object.
0
 
LVL 1

Expert Comment

by:tvanceplus
ID: 2812411
It could be overkill. I was not sure whether or not the fact that DWORD was an unsigned value would cause overflow for the integer conversion function parameter.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2812716
Good point.  if the DWORD is outside of the signed int range you would need to use i64toa().
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question