copy CString value to char
-
HI, i cannot copy CString value to char.but it show error.I typecast the CString value ,but still i get errors. Pls help me out. char cAlarmStatus; CString AlCond; if(...) AlCond = "HH"; else AlCond = "LL"; strcpy(objAlarmData->cAlarmStatus,(LPCTSTR)AlCond); I get error that cannot convert parameter one form char to char*. Pls help me how to copy this CString AlCond to cAlarmStatus
Anu
-
HI, i cannot copy CString value to char.but it show error.I typecast the CString value ,but still i get errors. Pls help me out. char cAlarmStatus; CString AlCond; if(...) AlCond = "HH"; else AlCond = "LL"; strcpy(objAlarmData->cAlarmStatus,(LPCTSTR)AlCond); I get error that cannot convert parameter one form char to char*. Pls help me how to copy this CString AlCond to cAlarmStatus
Anu
char T[100] = {0};
CString S = "Hello";
strcpy(T, S.GetString());Maxwell Chen
-
char T[100] = {0};
CString S = "Hello";
strcpy(T, S.GetString());Maxwell Chen
To add with Maxwell's answer, In your code you used 'char' and not 'char*'.. Try using as Maxwell said or you can allocate memory at runtime with the lenght of CString object and copy the string (but don't forget to release/delete the memory allocated)
Do your Duty and Don't expect the Result
-
HI, i cannot copy CString value to char.but it show error.I typecast the CString value ,but still i get errors. Pls help me out. char cAlarmStatus; CString AlCond; if(...) AlCond = "HH"; else AlCond = "LL"; strcpy(objAlarmData->cAlarmStatus,(LPCTSTR)AlCond); I get error that cannot convert parameter one form char to char*. Pls help me how to copy this CString AlCond to cAlarmStatus
Anu
What do you really need? I mean, you cannot usually copy the whole
CString
content to achar
variable (it can hold a single character), you need a character array or a pointer to dynamic allocated memory. On the other hand, you probably don't need at a CString object:const char * pszAlarmStatus;
if(...)
pszAlarmStatus = "HH";
else
pszAlarmStatus = "LL";that's all. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]