Document number: | N1982=06-0052 |
Date: | 2006-04-05 |
Project: | Programming Language C++ |
Reference: | ISO/IEC IS 14882:2003(E) |
Reply to: | Pete Becker |
Roundhouse Consulting, Ltd. | |
petebecker@acm.org |
Add the following to [lib.string.classes] at the end of the "Header <string> synopsis":
int stoi(string& str, int base = 10);
long stol(string& str, int base = 10);
unsigned long stoul(string& str, int base = 10);
long long stoll(string& str, int base = 10);
unsigned long long stoull(string& str, int base = 10);
float stof(string& str);
double stod(string& str);
long double stold(string& str);
string to_string(long long val);
string to_string(unsigned long long val);
string to_string(long double val);
int stoi(wstring& str, int base = 10);
long stol(wstring& str, int base = 10);
unsigned long stoul(wstring& str, int base = 10);
long long stoll(wstring& str, int base = 10);
unsigned long long stoull(wstring& str, int base = 10);
float stof(wstring& str);
double stod(wstring& str);
long double stold(wstring& str);
wstring to_wstring(long long val);
wstring to_wstring(unsigned long long val);
wstring to_wstring(long double val);
Add the following as a new subclause 21.3.7.10, "Numeric conversions":
int stoi(string& str, int base = 10); long stol(string& str, int base = 10); unsigned long stoul(string& str, int base = 10); long long stoll(string& str, int base = 10); unsigned long long stoull(string& str, int base = 10);
Effects: the first two functions call
strtol(str.c_str(), 0, base)
, and the last three functions callstrtoul(str.c_str(), 0, base)
,strtoll(str.c_str(), 0, base)
, andstrtoull(str.c_str(), 0, base)
, respectively. Each returns the converted result, if any, and erases the characters from the front ofstr
that were converted to get the result.Returns: the converted result.
Throws:
invalid_argument
ifstrtol
,strtoul
,strtoll
, orstrtoull
reports that no conversion could be performed. Throwsout_of_range
if the converted value is outside the range of representable values for the return type.float stof(string& str); double stod(string& str); long double stold(string& str);
Effects: the first two functions call
strtod(str.c_str(), 0)
, and the third function callsstrtold(str.c_str(), 0)
, respectively. Each returns the converted result, if any. They erase the characters from the front ofstr
that were converted to get the result.Returns: the converted result.
Throws:
invalid_argument
ifstrtod
orstrtold
reports that no conversion could be performed. Throwsout_of_range
ifstrtod
orstrtold
setserrno
toERANGE
.string to_string(long long val); string to_string(unsigned long long val); string to_string(long double val);
Returns: each function returns a
string
object holding the character representation of the value of its argument that would be generated by callingsprintf(buf, fmt, val)
with a format specifier of"%lld"
,"%ulld"
, or"%f"
, respectively.Throws: nothing.
int stoi(wstring& str, int base = 10); long stol(wstring& str, int base = 10); unsigned long stoul(wstring& str, int base = 10); long long stoll(wstring& str, int base = 10); unsigned long long stoull(wstring& str, int base = 10);
Effects: the first two functions call
wcstol(str.c_str(), 0, base)
, and the last three functions callwcstoul(str.c_str(), 0, base)
,wcstoll(str.c_str(), 0, base)
, andwcstoull(str.c_str(), 0, base)
, respectively. Each returns the converted result, if any, and erases the characters from the front ofstr
that were converted to get the result.Returns: the converted result.
Throws:
invalid_argument
ifwcstol
,wcstoul
,wcstoll
, orwcstoull
reports that no conversion could be performed. Throwsout_of_range
if the converted value is outside the range of representable values for the return type.float stof(wstring& str); double stod(wstring& str); long double stold(wstring& str);
Effects: the first two functions call
wcstod(str.c_str(), 0)
, and the third function callswcstold(str.c_str(), 0)
, respectively. Each returns the converted result, if any. They erase the characters from the front ofstr
that were converted to get the result.Returns: the converted result.
Throws:
invalid_argument
ifwcstod
orwcstold
reports that no conversion could be performed. Throwsout_of_range
ifwcstod
orwcstold
setserrno
toERANGE
.wstring to_wstring(long long val); wstring to_wstring(unsigned long long val); wstring to_wstring(long double val);
Returns: each function returns a
wstring
object holding the character representation of the value of its argument that would be generated by callingwsprintf(buf, fmt, val)
with a format specifier ofL"%lld"
,L"%ulld"
, orL"%f"
, respectively.Throws: nothing.