itoa not declared in this scope

I have included

#include <stdio.h>
#include <stdlib.h>

in my .h file and in my .cc file I have a function below and when compiled it generates:

 error: âitoaâ was not declared in this scope

String FishBowl::descrip() const{
	char buffer[33];
	itoa(aq_width, buffer,10);
	String width(buffer);
	String result = "\'" + width + "mm high fish bowl" +"\'";
	return result;

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

itoa is not a std function.. better use sprintf.

or better use snprintf  to prevent overflow.... or implement your own itoa.
kuntilanakAuthor Commented:
how would you change the code above so I can use sprintf? it doesn't return a char*
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

#include <string.h>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kuntilanakAuthor Commented:
I have read the link you posted above, but still it doesn't make sense why it cant find itoa
In standard C++ you can generally use a std::ostringstream to convert
from number to string, but std::ostringstream only supports three
radixes: decimal (by std::dec), octal (by std::oct) and hex (std::hex).

For C++ avoid using itoa. Preference is to use boost, or failing that, a stringstream.
std::string val = boost::lexical_cast<std::string>(number);
where are you compiling the code ? Which OS ?
may be your OS's standard C library doesnt implement this function.

Open the stdlib.h file and see if you can see any declaration of itoa function.
i tested it on my AIX box. Its doesnt implement itoa function.

# cc new.c
ld: 0711-317 ERROR: Undefined symbol: .itoa
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.

So some libraries do define.. some don't. Thats why people suggest not to use itoa, because then the program will not be portable. sprintf is a std function and if you use that, it will be portable to all the machines.
evilrixSenior Software Engineer (Avast)Commented:
>> but still it doesn't make sense why it cant find itoa

As shajithchandran said, itoa isn't part of the C standard library. What you can deduce from this is (a) your compiler may not have support for it  and (b) even if it does the header files and libraries you need to include to use it are going to be compiler specific -- so you will need to refer to your compilers documentation.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.