_itoa in the g++

来源:互联网 发布:mac mini 音频输出 编辑:程序博客网 时间:2024/05/01 16:12

itoa is not ansi C standard and you should probably avoid it. Here are some roll-your-own implementations if you really want to use it anyway:

http://www.jb.man.ac.uk/~slowe/cpp/itoa.html

If you need in memory string formatting, a better option is to use snprintf. Working from your example:

#include <stdio.h>#include <stdlib.h>int main (){  int i;  char buffer [33];  printf ("Enter a number: ");  scanf ("%d",&i);  snprintf(buffer, sizeof(buffer), "%d", i);  printf ("decimal: %s\n",buffer);  return 0;}
原创粉丝点击