c++ 将字符串数字转化为整形int

函数atoi 将字符串转化为int

int atoi (const char * str);


需要库 #include


例子:

/* atoi example */
#include       /* printf, fgets */
#include      /* atoi */

int main ()
{
  int i;
  char buffer[256];
  printf ("Enter a number: ");
  fgets (buffer, 256, stdin);
  i = atoi (buffer);
  printf ("The value entered is %d. Its double is %d.\n",i,i*2);
  return 0;
}

你可能感兴趣的:(C++)