字符串转数字
#include<iostream>
#include<string>
#include <stdio.h>
using namespace std;
int main()
{
char str[]= "123456";
int a;
sscanf(str, "%d", &a); //换成%x等可以实现进制之间的转换
cout << a;
return 0;
}
数字转字符串
数字转字符串:使用sprintf()函数
#include <iostream>
#include <string>
using namespace std;
int main(){
char str[10];
int a=1234321;
sprintf(str,"%d",a);
cout<<str<<endl;
//char str[10];
//int a=20;
//sprintf(str,"%x",a);//10进制转换成16进制,如果输出大写的字母是sprintf(str,"%X",a)
//cout<<str;
return 0;
}