s取一个得到char,char转int
不需要函数,直接-‘0’
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s = "1234";
char t = s[1];
int i = t;
cout<<i-'0';
return 0;
}
substr和string转int
#include<iostream>
using namespace std;
int main()
{
string s = "1234";
string start = s.substr(0,1);
string end = s.substr(s.size()-1,1);
int a = stoi(start);
int b = stoi(end);
cout<<start<< " " << end<<endl;
cout<<a<< " " << b;
return 0;
}