Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'itoa': The POSIX name for this item is deprecated

Tags:

c

itoa

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.

like image 552
Dan Murphy Avatar asked Oct 24 '17 17:10

Dan Murphy


People also ask

Is ITOA deprecated?

In information technology (IT), deprecation means that although something is available or allowed, it is not recommended or that -- in the case where something must be used -- to say it is deprecated means that its failings are recognized.

Is Posix deprecated?

The POSIX standard for APIs was developed over 25 years ago. We explored how applications in Android, OS X, and Ubuntu Linux use these interfaces today and found that weaknesses or deficiencies in POSIX have led to divergence in how modern applications use the POSIX APIs.


2 Answers

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  
like image 95
Weather Vane Avatar answered Oct 16 '22 12:10

Weather Vane


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.

like image 4
Edwin Buck Avatar answered Oct 16 '22 10:10

Edwin Buck