I want to cast a long to a cstring.
I've been struggling with this for a while and I've seen so many variants of solving this problem, more or less riddled with hassle and angst.
I know the question seems subjective, but it really shouldn't be in my opinion. There must be a way considered to be the best when the circumstances involve MFC and the standard libs that come with those circumstances.
I'm looking for a one-line solution that just works. Sort of like long.ToString() in C#.
_ltoa() — Convert Long Integer to String h> char *_ltoa(long value, char *string, int radix); Note: The _ltoa function is supported only for C++, not for C.
To use CString , include the atlstr. h header. The CString , CStringA , and CStringW classes are specializations of a class template called CStringT based on the type of character data they support. A CStringW object contains the wchar_t type and supports Unicode strings.
The cstring header file contains definitions for C++ for manipulating several kinds of strings. Include the standard header into a C++ program to effectively include the standard header <string. h> within the std namespace.
cstring is the header file required for string functions. This function Returns a pointer to the last occurrence of a character in a string.
It's as simple as:
long myLong=0;
CString s;
// Your one line solution is below
s.Format("%ld",myLong);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With