string转int

atoi(字符串.c_str())

int转string

to_string(整数)

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. string s = "123";
  6. int a = atoi(s.c_str()); // string 转 int
  7. cout<<"(int类型) a = "<<a<<endl;
  8. string str = to_string(321); // int 转 string
  9. cout<<"(string类型) str = "<<str<<endl;
  10. return 0;
  11. }

image.png