0

I am working with C++ with Visual studio 2008 IDE. I need to convert long to a CString (or some other format that will work well with CString). Once I have it converted, I need to concatenate it to another CString. Something like this (but open to suggestions):

CString = CString + convertToCString(long)

Question 1: What is the best way (and please explain why an approach is superior over others) for the conversion?

For now, I am using _ltow_s:

CString = CString + _ltow_s (long)

_ltow_s is returning WCHAR. So I end up with:

CString = CString + WCHAR

Question 2: Is that concatenation safe and will yield the desired result? Is the concatenation of ‘CString + WCHAR’ results with a valid CString?

Question 3: If we are going down the rout of using _ltow_s, what is the buffer size that needed to be allocated? 32? also, is there a define for base 10 (decimal)?

Update: I found this thread: How to cast a LONG to a CString? I like it as it gives many options. What is still missing is what is the preferred way for different scenarios (within reason). Robustness, safety etc...

Community
  • 1
  • 1
Rotem Varon
  • 1,597
  • 1
  • 15
  • 32

1 Answers1

1

Try this:

CString cstr;
cstr.Format("%ld", long);
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Robert
  • 1,235
  • 7
  • 17