zoukankan      html  css  js  c++  java
  • 怎样将一个整数转化成字符串数,并且不用函数itoa

     1 #include<iostream>
     2 using namespace std;
     3 int main()
     4 {
     5     int num = 12345, j = 0, i = 0;
     6     char temp[7], str[7];
     7 
     8     while (num)
     9     {
    10         temp[i] = num % 10 + '0';
    11         i++;
    12         num = num / 10;
    13     }
    14     temp[i] = 0;
    15     printf("temp=%s
    ", temp);
    16     i = i - 1;
    17     printf("temp=%d
    ", i);
    18     while (i >= 0)
    19     {
    20         str[j] = temp[i];
    21         j++;
    22         i--;
    23     }
    24     str[j] = 0;
    25     printf("string=%s
    ", str);
    26     system("PAUSE");
    27     return 0;
    28 }
    #include<iostream>
    using namespace std;
    int main (void)
    {
        int num = 100;
        char str[25];
        itoa(num, str, 10);
        cout<<num<<" "<<str;
        return 0;
    }


    itoa()函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转移数字时所用的基数。在上例中,转换基数为10。10:十进制;2:二进制...

  • 相关阅读:
    Linux进程间通信(IPC)
    mq_setattr
    mq_getattr
    mq_unlink
    mq_receive
    mq_send
    mq_close
    POSIX消息队列
    mq_open
    C语言关键字
  • 原文地址:https://www.cnblogs.com/wft1990/p/6805413.html
Copyright © 2011-2022 走看看