Disclaimer: links to cppreference.com
So, I knew for a while that std :: atoi was deprecated, and it was recommended to use std :: strtol .
C ++ 11 introduced std :: stoi , and I'm trying to figure out why you decided to use it on top std::strtol.
std::strtol
From what I understand, this is what stoi calls strtol, but throws exceptions. It also returns an integer instead of a long one.
Are these the main differences that I am missing?
, std::stoi std::string ( .c_str()) size_t, .
std::stoi
std::string
.c_str()
size_t
.
, stoi std::string, .c_str() , .
stoi
long, stol ( stod, stof stold, stoul, stoll double, float, long double, unsigned long long long ).
long
stol
stod
stof
stold
stoul
stoll
double,
float
long double
unsigned long
long long
std::stoi(), std::basic_string, int. long, std::stol().
std::stoi()
std::basic_string
int
std::stol()
stoi() strtol(), std:: invalid_argument . , GNU libstd++ . : "what(): stoi"
std:stoi C <string>, - , C. () std: string , ++.
std:stoi
<string>
, , std:: FromString template, , . , ToString .
int i = std::FromString <int> (std::string ("2")) int j = std::FromString <int> ("2") std::string = ToString <double> (3.14159)
, , , , , from_string to_string.
, . , , , ?