The deciding line is
if ( swscanf_s(s, L"%s %f %s %d", &st1, &doub, &st2, &integ )!= 4 )
As Nithin has written in his post, the second argument needs to be a wide character string and hence the L"... is required.
All other suggestions are more or less useless. For example, the line
CString s ="first:25.5,second,15";
it okay, because the CString knows how to convert from a char string to a wide-char string. All is ok there.
There are however a couple of other quirks in this example. First of all, if you are using swscanf
_s the string arguments require an additional specifier of the buffer length. For example:
wchar_t st1 [50];
wchar_t st2 [50];
if (swscanf_s(s, L"%s %f %s %d", &st1, 50, &doub, &st2, 50, &integ )!= 4 )
Next, your input does not really match the format specifier. The
%s
consumes all characters up to the next white space. Hence you better change the input to:
CString s ="first 25.5 second 15";
And finally, if doub is a double variable, you should specify "%lf" as format specifier, otherwise swscanf_s assumes that you are passing the address of a float variable.
With all these changes the example will run as expected.