文字列からスカラー (char、short、int...) にデータを抽出するとき、取得したい値が型の制限を超えているかどうかを簡単に知るにはどうすればよいですか?
unsigned char function(void)
{
std::string str = "259";
std::ostringstream os(str);
unsigned char scalar; // could also be short, int, float or double
if (str > /* limit of char */)
{
/* throw exception */
}
os >> scalar;
return scalar;
}