C語言轉換形式:
... std::string str; int i = atoi(str.c_str()); ...
其參數只能是字符數組,不能是string類型,還有一類函數strtod
atof() 將字符串轉換為雙精度浮點型值
atoi() 將字符串轉換為整型值
atol() 將字符串轉換為長整型值
strtod() 將字符串轉換為雙精度浮點型值,並報告不能被轉換的所有剩余數字
strtol() 將字符串轉換為長整值,並報告不能被轉換的所有剩余數字
C++轉換格式(C++11):
... std::string str; int i = std::stoi(str); ...
同樣, 可以使用 stol(long), stof(float), stod(double) 等.
參考鏈接:
1. https://blog.csdn.net/caroline_wendy/article/details/29390573