I'm working on Eclipse inside Ubuntu environment on my C++ project.
I use the itoa
function (which works perfectly on Visual Studio) and the compiler complains that itoa
is undeclared.
I included <stdio.h>
, <stdlib.h>
, <iostream>
which doesn't help.
itoa()
is not part of any standard so you shouldn't use it. There's better ways, i.e...C:
C++:
itoa depends on compiler, so better use the following methods :-
method 1 :If you are using c++11, just go for std::to_string. It will do the trick.
method 2 :sprintf works for both c & c++. ex- ex - to_string
Note - compile using -std=c++0x.
C++ sprintf:
Boost way:
string str = boost::lexical_cast<string>(n);
Did you include stdlib.h? (Or rather, since you're using C++, cstdlib)
www.cplusplus.com says:
This function is not defined in ANSI-C and is not part of C++, but is supported by some compilers.
Therefore, I'd strongly suggest that you don't use it. However, you can achieve this quite straightforwardly using
stringstream
as follows:you may use sprintf
output would be :hell9