ltoa 实现 长整型转化为字符串 源码(类似itoa)

来源:互联网 发布:朝鲜核讹诈中国知乎 编辑:程序博客网 时间:2024/06/05 00:57


#include<iostream>#include <string.h>using namespace std;char *ltoc(long a,char *s){    if (s == NULL)    {        return 0;    }    unsigned long b;        if (a == LONG_MIN)    {        b = LONG_MAX + 1UL;    }    if (a<0)    {        b = -a;    }    else    {        b=a;    }    *--s = '\0';    do    *--s = b%10 +'0';    while ((b/=10) >0);        if (a < 0)    {        *--s ='-';    }    return s;}int main(int argc , const char * argv[]){    long a = -9876543210;    char *b =new char[43];    b =  ltoc(a, b);    cout<<b;    return 0;}


0 0
原创粉丝点击