数字和字符串互相转换

/*数字转换成字符串*/

#include <iostream>

#include <stdio.h>

using namespace std;



int main()

{

	int num = 12345;

	char str[20];



	sprintf(str, "%d", num);



	cout << str;

}

 

 

 

/*数字转换成字符串*/

#include <iostream>

#include <stdio.h>

using namespace std;



int main()

{

	int num;

	char str[20] = "12345";



	sscanf(str, "%d", &num);

	cout << sizeof(num) << "" << num;

}

你可能感兴趣的:(字符串)