C++_数据类型转换
int main() { //字符串转化成整数 int A; string s; cin >>s; stringstream seam; //随意的什么类型都可以输入 seam<<s; //向流中传入值s 字符串型 seam>>A; //向A中写入值A 整型 cout <<A; ** //到此字符串转换成整数成功** //整数装换成字符串 int B; cin >>B; seam.clear(); //重复利用的时候,清空缓存 seam<<B; seam>>s; cout <<s; } input:1234(字符串) 对应output:1234整数 input:6547(整数) 对应output:6547(字符串) 除此之外的另外2种函数转换方式: - 字符串转换成整数 atoi include<iostream> include<string> include<stdio.h> //printf的头文件 include <stdlib.h> //atoi的头文件 using namespace std; int main(){ /****************字符串转换成整数*****************/ //方法一:atoi函数 字符数组转换成整数 char str1[ 10 ]= "123" ; //实际上4个字符 int a = atoi(str1); printf