My question is related to this older question Format specifiers for uint8_t, uint16_t, ...?
Just to recap the original question was related to how to use the specifiers for uint8_t, uint16_t, uint32_t and uint64_t with a scanf?
The answer to the question was as follows:
sscanf (line, "Value of integer: %" SCNd32 "\n", &my_integer);
But does anyone know how to do this but resulting in a wide string?
ie
std::wstring line;
swscanf (line.c_str(), L"Value of integer: %" SCNd16 L"\n", &my_integer);
The sbove line gives me a concatenating error. I believe because the SCNd16 is just not intended for a widestring?
Currently my solution is to create the std::string in the original answer and then convert it to a wide string
sscanf_s(line.c_str(), "%" SCNd16 "\n", &sixteenBitInteger)
// code here to check for EOF and EINVAL
//then I convert it
typedef std::codecvt_utf8<wchar_t> ConverterType;
std::wstring_convert<ConverterType, wchar_t> converter;
std::wstring convertedString = converter.from_bytes(line);
but it's rather ugly and I am sure there must be a more polished way to do this conversion? If it helps to understand my use, I am using the uint16_t type to store the port number for a web server but I want to be able to convert it to a wide string as that is the expected display type. I am also using C++11 if that changes the answer at all and I do have access to the boost libraries although I would rather not use them.