'itoa': The POSIX name for this item is deprecated
Asked Answered
A

3

10

I'm trying to convert an int into a string by doing this:

int id = 12689;
char snum[MAX];
itoa(id, snum, 10);

I get the following error:

'itoa': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _itoa.

Aftershaft answered 24/10, 2017 at 17:20 Comment(7)
Are you using visual studio?Distributary
Possible duplicate of How to convert an int to string in CRutilant
Well, do what the compiler tells you.Sthenic
@Distributary yes visual studioAftershaft
Regardless of what Visual Studio tells you, there's no standard function named itoa or _itoa. Unless you are looking for something fancy, snprintf() should be good enough.Rachealrachel
Then use #define _CRT_NONSTDC_NO_DEPRECATE before including header files.Distributary
Perfect thanks guys got it fixedAftershaft
C
14

That is MSVC doing that to you. If you add the following line before any library #includes

#define _CRT_NONSTDC_NO_DEPRECATE

the warning is suppressed, similar for many other functions too.

Moreover if you add these two lines as well, MSVC will stop telling you to use scanf_s instead of the standard function scanf (and others).

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE  
Cryoscope answered 24/10, 2017 at 17:25 Comment(0)
U
6

Please use snprintf, it is more portable than itoa.

char buffer[10];
int value = 234452;
snprintf(buffer, 10, "%d", value);

itoa is not part of standard C, nor is it part of standard C++; but, a lot of compilers and associated libraries support it.

Udo answered 24/10, 2017 at 17:31 Comment(1)
The comment to rename it is just to bring the function name in line with C / C++'s naming conventions with regards to proceeding underscores _itoa preferred over itoa; but, in either case, the existence of a itoa function in either case is not standard C, even if it is common. It is compiler dependent, and the kind of code that needs rewritten to make porting your application easier.Udo
F
1

There has never been a standard itoa function in C standard library. So, trying to use it is not a good idea in any case. In C you have functions from sprintf family that will happily perform that conversion for you.

Fuchs answered 24/10, 2017 at 17:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.