From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with converting from CString to char*

hello people,

 

I try to cast a CString in char* but it only take the first character

 

CString sox =(CString)"A060,"  ;

char* pChar = (char*)(LPCTSTR)(CString)sox ;

 

after i built it, there is only the character "A"  in pChar and not "A060,"

 

 

HELP !!!!

0 Kudos
Message 1 of 2
(4,882 Views)

Hi,

What do you use to display pChar?

As pChar is pointing a Cstring, you have to display it as a CString.

If you use a printf it will display A, you have to use _tprintf.

source: https://msdn.microsoft.com/en-us/library/ms174288.aspx

Example:

int main()
{
    CString sox =(CString)"A060,"  ;
    char* pChar = (char*)(LPCTSTR)(CString)sox ;
    _tprintf(_T("char=%s\n"), pChar);
}

Result:

char= A060.

 

Best regards,

Jovan N. - Application Engineering
0 Kudos
Message 2 of 2
(4,736 Views)