Porting itoa Windows STL Code to Linux

Porting itoa Windows STL Code to Linux

There is no default itoa implementation in the STL under Linux. If you include , it won’t work. If you disable the STL from the GCC command line, you lose the STL and your code will not be portable. This tip can help you port your code from Windows to Linux in such a situation.

#if defined(__linux__)#define _itoa   itoachar* itoa(int value, char*  str, int radix){    int  rem = 0;    int  pos = 0;    char ch  = '!' ;    do    {        rem    = value % radix ;        value /= radix;        if ( 16 == radix )        {            if( rem >= 10 && rem <= 15 )            {                switch( rem )                {                    case 10:                        ch = 'a' ;                        break;                    case 11:                        ch ='b' ;                        break;                    case 12:                        ch = 'c' ;                        break;                    case 13:                        ch ='d' ;                        break;                    case 14:                        ch = 'e' ;                        break;                    case 15:                        ch ='f' ;                        break;                }            }        }        if( '!' == ch )        {            str[pos++] = (char) ( rem + 0x30 );        }        else        {            str[pos++] = ch ;        }    }while( value != 0 );    str[pos] = '' ;    return strrev(str);}#endif
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several