Search code examples
c++cstring

CStringT to char[]


I'm trying to make changes to some legacy code. I need to fill a char[] ext with a file extension gotten using filename.Right(3). Problem is that I don't know how to convert from a CStringT to a char[].

There has to be a really easy solution that I'm just not realizing...

TIA.


Solution

  • Well you can always do this even in unicode

    char str[4];
    strcpy( str, CStringA( cString.Right( 3 ) ).GetString() );
    

    If you know you AREN'T using unicode then you could just do

    char str[4];
    strcpy( str, cString.Right( 3 ).GetString() );
    

    All the original code block does is transfer the last 3 characters into a non unicode string (CStringA, CStringW is definitely unicode and CStringT depends on whether the UNICODE define is set) and then gets the string as a simple char string.