How to convert a string to char
-
Hi, Can you say How to convert a CString value to a char value. Thanks in advance.
-
Hi, Can you say How to convert a CString value to a char value. Thanks in advance.
-
Hi, Can you say How to convert a CString value to a char value. Thanks in advance.
LPSTR GetBuffer(int;
KIRAN PINJARLA
-
Hi, Can you say How to convert a CString value to a char value. Thanks in advance.
Hi, This link may be helpfull to u? Look into this.. http://www.flounder.com/cstring.htm regds, Ashok
-
Hi, Can you say How to convert a CString value to a char value. Thanks in advance.
Two people have correctly told you how to get a char *, although neither told you that you need to call ReleaseBuffer() on the string when you're done with it. But if you want to access a single char from the string, you can use index notation to access one character at a time. CString s("sucka"); char u = s[1]; This is assuming a non Unicode build, of course.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Two people have correctly told you how to get a char *, although neither told you that you need to call ReleaseBuffer() on the string when you're done with it. But if you want to access a single char from the string, you can use index notation to access one character at a time. CString s("sucka"); char u = s[1]; This is assuming a non Unicode build, of course.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Nor did they mention that if you don't need to modify the string a simple assignment will do the trick. i.e.
LPCTSTR pStr = s;
Steve
-
Two people have correctly told you how to get a char *, although neither told you that you need to call ReleaseBuffer() on the string when you're done with it. But if you want to access a single char from the string, you can use index notation to access one character at a time. CString s("sucka"); char u = s[1]; This is assuming a non Unicode build, of course.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Well just for curiosity sake, I guess one needs to call ReleaseBuffer() only if the buffer supplied is manipulated with, like data is altered. Does one have to always call ReleaseBuffer(), i mean if he is just calling GetBuffer() just to convert it to form easy for display or copy etc??
-
Well just for curiosity sake, I guess one needs to call ReleaseBuffer() only if the buffer supplied is manipulated with, like data is altered. Does one have to always call ReleaseBuffer(), i mean if he is just calling GetBuffer() just to convert it to form easy for display or copy etc??
Every call to
GetBuffer
should have a matching call toReleaseBuffer
.GetBuffer
andReleaseBuffer
should only be used on code which alters the string. If you just want to inspect useoperator LPCTSTR
. Using this operator is automatic, ie:const char *pData = MyCString;
As Christian suggested however, both of these methods should only be use when using aCString
with code that knows nothing aboutCString
s - In general useCString
's member functions to manipulate it's contents.Steve
-
Every call to
GetBuffer
should have a matching call toReleaseBuffer
.GetBuffer
andReleaseBuffer
should only be used on code which alters the string. If you just want to inspect useoperator LPCTSTR
. Using this operator is automatic, ie:const char *pData = MyCString;
As Christian suggested however, both of these methods should only be use when using aCString
with code that knows nothing aboutCString
s - In general useCString
's member functions to manipulate it's contents.Steve
hey, thx for the info. will ensure that for further coding.
-
Well just for curiosity sake, I guess one needs to call ReleaseBuffer() only if the buffer supplied is manipulated with, like data is altered. Does one have to always call ReleaseBuffer(), i mean if he is just calling GetBuffer() just to convert it to form easy for display or copy etc??
cpp_prgmer wrote:
Does one have to always call ReleaseBuffer()
Yes. A call to GetBuffer requires a call to ReleaseBuffer. Failing to do so results in a memory leak.
cpp_prgmer wrote:
i mean if he is just calling GetBuffer() just to convert it to form easy for display or copy etc??
There is no need to call GetBuffer for thos purposes. CString has an (LPCTSTR) operator to convert to
const TCHAR*
implicitly, so in non-UNICODE builds, that operator returns aconst char*
.If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac