c++中string转double怎么弄list string 逗号分隔s=“af,12.3,1,dfg,222……”我要提取逗号间隔的数值为double谢谢

to_string - C++ Reference
std::to_string
string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);Convert numerical value to string
with the representation of val.
The format used is the same that
would print for the corresponding type:
type of valprintf equivalentdescription
int"%d"Decimal-base representation of val.
The representations of negative values are preceded with a minus sign (-).
long long"%lld
unsigned"%u"Decimal-base representation of val.
unsigned long"%lu
unsigned long long"%llu
float"%f"As many digits are written as needed to represent the integral part, followed by the decimal-point character and six decimal digits.
inf (or infinity) is used to represent infinity.
nan (followed by an optional sequence of characters) to represent NaNs (Not-a-Number).
The representations of negative values are preceded with a minus sign (-).
long double"%Lf
Parameters
Numerical value.
Return Value
object containing the representation of val as a sequence of characters.
123456789101112
// to_string example
#include &iostream&
// std::cout
#include &string&
// std::string, std::to_string
int main ()
std::string pi = "pi is " + std::to_string(3.1415926);
std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";
std::cout && pi && '\n';
std::cout && perfect && '\n';
Possible output:
pi is 3.141593
28 is a perfect number
Exceptions
may throw.
Write formatted data to string (function
)Convert numerical value to wide string (function
)
class templates:
functions:

我要回帖

更多关于 list转string逗号隔开 的文章

 

随机推荐