[C ++] "C ++ 17 Introduction to the classic" study notes 13 ---- will std :: string String conversion to numbers

In C ++, the string is converted to a digital several ways. But the string header file provides the easiest option.

Using std :: stoi () function to convert the string to an integer specified:

std::string s{"123"};
int i{ std::stoi(s) };

 Similarly, string header file provides stol (), stoll (), stoul (), stoull (), stof (), stod () and STOLD () function, which are included in the std namespace, respectively character string into a long, long long, unsigned long, unsigned long long, float, double, and long double type.

 


 

Guess you like

Origin blog.csdn.net/kingkee/article/details/94228265