What are the differences between std :: strtol and std :: stoi?

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.

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?

+4
source share
6 answers

Are these the main differences that I am missing?

, std::stoi std::string ( .c_str()) size_t, .

.

+7

, stoi std::string, .c_str() , .

long, stol ( stod, stof stold, stoul, stoll double, float, long double, unsigned long long long ).

+2

std::stoi(), std::basic_string, int. long, std::stol().

+2

stoi() strtol(), std:: invalid_argument . , GNU libstd++ . : "what(): stoi"

+1

std:stoi C <string>, - , C. () std: string , ++.

0

, , 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.

, . , , , ?

-2

All Articles