Convert number to string
Use the sprintf function, included in the stdio.h header file
Usage: sprintf (character array, number type, number to be converted)
Numbers are converted to strings and stored in character arrays
#include <cstdio>
using namespace std;
char s[10];
int main(void)
{
int n = 100;
sprintf(s, "%d", n);
printf("%s\n", s);
return 0;
}
Convert string to number
Use the atoi function, included in the algorithm header file
Usage: atoi (string to be converted)
Return the converted number
#include <cstdio>
#include <algorithm>
using namespace std;
char s[10] = {
"100"};
int main(void)
{
int n = atoi(s);
printf("%d\n", n);
return 0;
}