I have a string that looks like L"\"4\"" and want to parse it into an integer value.
std::wstring wsFoo(L"\"4\"");
int iSize = 1; // Number of characters the number will have
int iResult = -1;
swscanf_s(wsFoo.c_str(), L"\"%*d\"", iSize, &iResult);
wprintf_s(L"%d", iResult);
According to http://www.cplusplus.com/reference/clibrary/cstdio/printf/ the asterisk in %*d should mean: The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.
Yet the value of iResult will be displayed as -1 after this code snippet. Why?
I don’t know whether it helps, but I am using MSVC++ 2010.
This MSDN page explains the use of the * like:
Note that the format fields for printf and scanf are close but not identical.