How to convert a CString to a char
A string is a group of characters, a char is ONE character. What exactly are you trying to do?
To get a specific character from the CString you could use the GetAt-method or the []-operator.
To treat the CString as a const char*, just cast it to one. E.g. CString str = "asdf"; const char* sz = (const char*) str;
To convert the string "123" to the number 123 use the atoi-function.
To treat the CString as a const char*, just cast it to one. E.g. CString str = "asdf"; const char* sz = (const char*) str;
To convert the string "123" to the number 123 use the atoi-function.
I don''t know about CString''s but with regular STL string''s you can call string.c_str() to get the C-style string out of it.
that will give you an array of char''s.
-David
string s="Hello";const char* str = s.c_str();
that will give you an array of char''s.
-David
Use the convertion operator LPCTSTR
For instance
int MyInt = atoi((LPCTSTR)MyCString);
operator LPCTSTR gets a const char* buffer.
(LPCTSTR) is implied on most calls requiring a const char*.
If you need a char * (one that you can write to) to modify it, use GetBuffer and ReleaseBuffer if I remember correctly.
For instance
int MyInt = atoi((LPCTSTR)MyCString);
operator LPCTSTR gets a const char* buffer.
(LPCTSTR) is implied on most calls requiring a const char*.
If you need a char * (one that you can write to) to modify it, use GetBuffer and ReleaseBuffer if I remember correctly.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement