C++字符串类型转换函数

109 阅读1分钟

字符串转换有几个常用函数,如stoi,stof,stol,stod,stoll,stoul等(分别为string to int, string to float, string to long, string to double, string to long long, string to unsigned long)。
给这类函数传递的参数统一为str,ptr,base。str是要转换的字符串;ptr可以为空指针,如果不为空,则指向str中数字后的第一个字符的位置;base指明数字的进制(基数),默认为十进制。