1.使用sstreamm类整数转换为字符串
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #include<iostream> #include<sstream> using namespace std; void is2(int x,string &s_basic) { stringstream ss; ss<<x; ss>>s_basic; } int main() { string s1; int n=123456; is2(n,s1); cout<<s1[3]; return 0; }
|
1.使用sstreamm类字符串转换为整数,但字符串存储的一定要是数字否则输出零
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #include<iostream> #include<sstream> using namespace std; void is2(int &x,string s_basic) { stringstream ss; ss<<s_basic; ss>>x; } int main() { string s1="1234456"; int n; is2(n,s1); cout<<n; return 0; }
|