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

why??
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

kuntilanakAsked:
Who is Participating?
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.

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

sprintf(aval,"%d",ival);
0
shajithchandranCommented:
or better use snprintf  to prevent overflow.... or implement your own itoa.
0
kuntilanakAuthor Commented:
how would you change the code above so I can use sprintf? it doesn't return a char*
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

nole172Commented:
#include <string.h>
0
shajithchandranCommented:
snprintf(buffer,32,"%d",aq_width);
0

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
0
Sarika30Commented:
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);
0
shajithchandranCommented:
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.
0
shajithchandranCommented:
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.
0
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.
0
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
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.