Hello william_jwd.
I got this after using your code:
`itoa' undeclared (first use this function)
Any suggestion ? Do I need to incude some class ?
Main Topics
Browse All TopicsThis is my program
******************
#include <iostream>
using namespace std;
int main()
{
int i = 0;
string message = "";
// message = the value of "i" converted to string.
return 1;
}
********************
I want to convert "i" to string, how ? Please remember to add the class that I need to add...
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
My program:
********************
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int i = 0;
string message = "";
message = itoa(i);
return 1;
}
**********************
When trying to compile with: g++ test.cpp -o test I get this error:
**********************
`itoa' undeclared (first use this function)
What compiler are you using?
For Microsoft, the function is
char *_itoa( int value, char *string, int radix);
Note the underscore.
Parameters:
value :Number to be converted.
string :String result.
radix :Base of value; must be in the range 2 – 36.
So do something like
int i = 123;
char buf[100];
_itoa(i, buf, 10);
buf now contains the string.
My code is simple:
******************
#include <iostream>
using namespace std;
int main()
{
char * message;
string temp = "HELLO";
// Here "message" should get the word "HELLO" .... how ?
return 1;
}
**********************
How do I make my "message" to get the value of temp, so when I say:
cout << message
then I get "HELLO" ?
Wow what a confusing thread this has turned into.
Here's what you need:
--------8<--------
#include <iostream>
#include <sstream>
int main()
{
int i = 0;
std::ostringstream ostr; // This is an output stream - cum - string
ostr << i; // Output the number to the string stream
std::string str = ostr.str(); // Get the output string
std::cout << "Your string is \"" << str << "\"\n"; // Bob's your uncle
}
--------8<--------
In fact, the itoa function is not defined in ANSI C, but supported by some compilers like MSVC, but not g++ (see http://www.cplusplus.com/r
You can write your self this itoa function. In the following example, ___char *buff___ must be allocated before calling of this function.
char * itoa(int n, char *buff, int radix)
// convert a positive integer n to char *buff
// for instant, this function work with radix <= 10;
// a little change to run with radix > 10
{
int q, r;
int i = 0;
char tmp[33]; // for radix = 2 and 32 bits computer
do{
q = int(n / radix);
r = n % radix;
n = q;
tmp[i++] = 48 + r;
}while(q > 0);
int j;
for(j = 0; j < i; j++){
buff[j] = tmp[i - j - 1];
}
buff[j] = NULL;
return buff;
}
Hope enjoy it.
Business Accounts
Answer for Membership
by: william_jwdPosted on 2004-03-25 at 03:56:12ID: 10676090
string message = itoa(i);