I wanna use C libraries such as cstdio
and cstdlib
, and I can use both:
int i = atoi("123");
or
int i = std::atoi("123");
Both work fine. Which one should I use? Are they equivalent?
I wanna use C libraries such as cstdio
and cstdlib
, and I can use both:
int i = atoi("123");
or
int i = std::atoi("123");
Both work fine. Which one should I use? Are they equivalent?
For portability, you should use the std
versions, for two reasons:
atoi
, but mathematical functions, for example) have extra overloads in C++. At least one popular library dumps the C overload into the global namespace, but not the C++ overloads. This means your code might change its behaviour in bizarre and infuriating ways if you change implementations.