C++中string转int

利用auto()函数
#include <iostream>
using namespace std;

int main()
{
    int num;
    string st = "100";
    
    num = atoi(st.c_str());
    
    return 0;
}
字符串数字前的'+','-',会决定转化后数字的正负

当字符不是纯数字字符时

 

posted @ 2022-05-14 15:49  B0mbax  阅读(40)  评论(0编辑  收藏  举报