I am using C++ 14
on clang
& gcc
. I have an std::string
which I need to convert to unsigned short
I am doing it the following way.
unsigned short u_var = 1234; //some default value
std::string str = "5678"; //some default value
u_var = (unsigned short) std::strtoul(str.c_str(), NULL, 0);
I found this from here.
However, I get the following warning doing this
Semantic issue
warning: use of old-style cast
The warning appears for both clang
& gcc
. What is wrong in what I doing? Is there is a better way to do this without any risk or a warning?
Also looking at the list of casting methods here, there seems to be no cast option available for std::string
to unsigned short
.