为什么没有std :: stou? [英] Why is there no std::stou?
问题描述
C ++ 11添加了一些新的字符串转换函数:
C++11 added some new string conversion functions:
http://en.cppreference.com/w/cpp/string/basic_string/stoul
它包括stoi(string to int ),stol(string to long),stoll(string to long long),stoul(string to unsigned long),stoull(string to unsigned long long)。值得注意的是它的缺乏是一个stou(字符串到无符号)函数。是否有某种原因不需要它,但所有其他的都是?
It includes stoi (string to int), stol (string to long), stoll (string to long long), stoul (string to unsigned long), stoull (string to unsigned long long). Notable in its absence is a stou (string to unsigned) function. Is there some reason it is not needed but all of the others are?
相关:否sto {short,unsigned short}。函数在C ++ 11?
推荐答案
最好的答案是C库没有相应的 ; strtou
&,并且C ++ 11字符串函数都是围绕C库函数的非常隐蔽的包装: std :: sto *
函数镜像 strto *
和 std :: to_string
函数使用 sprintf
。
The most pat answer would be that the C library has no corresponding “strtou
”, and the C++11 string functions are all just thinly veiled wrappers around the C library functions: The std::sto*
functions mirror strto*
, and the std::to_string
functions use sprintf
.
编辑:KennyTM指出, stoi
和 stol
使用 strtol
作为底层转换函数,但它仍然是神秘的为什么存在使用 strtoul
的 stoul
,没有相应的 stou
。
As KennyTM points out, both stoi
and stol
use strtol
as the underlying conversion function, but it is still mysterious why while there exists stoul
that uses strtoul
, there is no corresponding stou
.
这篇关于为什么没有std :: stou?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!