news.hku.hk
2004-05-01 16:20:20 UTC
Excuse me, i write the following function to add comma for integers
but the unix server said:
In function `class string comma(int)':
implicit declaration of function `int itoa(...)'
________________________________
string comma(int a){
char to_string[50];
string s_a = itoa(a, to_string, 10);
if (a>1000000000){
s_a.insert(s_a.length()-9, ",");
s_a.insert(s_a.length()-6, ",");
s_a.insert(s_a.length()-3, ",");
return (s_a);
}
else if (a>1000000){
s_a.insert(s_a.length()-6, ",");
s_a.insert(s_a.length()-3, ",");
return (s_a);
}
else if (a>1000){
s_a.insert(s_a.length()-3, ",");
return (s_a);
}
else return (s_a);
}
_____________________________
do i use itoa wrongly or i miss anything, i've already include the header
#include <cstdlib>
Thanks
but the unix server said:
In function `class string comma(int)':
implicit declaration of function `int itoa(...)'
________________________________
string comma(int a){
char to_string[50];
string s_a = itoa(a, to_string, 10);
if (a>1000000000){
s_a.insert(s_a.length()-9, ",");
s_a.insert(s_a.length()-6, ",");
s_a.insert(s_a.length()-3, ",");
return (s_a);
}
else if (a>1000000){
s_a.insert(s_a.length()-6, ",");
s_a.insert(s_a.length()-3, ",");
return (s_a);
}
else if (a>1000){
s_a.insert(s_a.length()-3, ",");
return (s_a);
}
else return (s_a);
}
_____________________________
do i use itoa wrongly or i miss anything, i've already include the header
#include <cstdlib>
Thanks