[C/C++] °ÑÒ»¸öÕûÐÍÕûÊýת³É×Ö·û´®
ÎÊÌâÃèÊö£ºÐ´Ò»¸öº¯Êý£¬½ÓÊÜÒ»¸öÕûÊý£¨¼Ù¶¨ÓÃint±íʾ£©£¬Êä³ö¸ÃÕûÊýµÄ×Ö·û´®ÐÎʽ¡£²ÉÓÃÈçϺ¯ÊýÔÐÍ£º
void itoa ( int val, char* buf );
ÕâÀï¼Ù¶¨buf×ã¹»´óÒÔÈÝÄÉÈκÎintÀàÐÍÊýÖµµÄ×Ö·û´®¡£
Õâ¸öÎÊÌ⣬³õ¿´ºÃÏñûÓÐʲôÄѶȡ£Èç¹ûÊÇ0£¬¾ÍÖ±½ÓÊä³ö'0'£»Èç¹ûÊÇÕýÊý£¬¾Íͨ¹ýÈ¡Ä£(%)ºÍÇóÉÌ(/)ÔËËã¿ÉÒÔÖðλȡµÃ¸ÃÕûÊýµÄÊý×Ö£¬²¢°ÑËüÃǷŵ½bufÖÐÈ¥£»Èç¹ûÊǸö¸ºÊý£¬¾ÍÏÈת³ÉÕýµÄ£¬È»ºóÔÚ×îºóÊä³öʱ¼ÓÈ븺ºÅ¡£°´ÕÕÕâ¸ö˼·£¬¿ÉÒÔдÏÂÈçÏ´úÂ룺
void itoa_flawed(int val, char* buf)
{
// deal with special case
if(val == 0)
{
buf[0] = '0';
buf[1] = '\0';
return;
}
bool negative = (val < 0);
int abs_val = negative ? -val : val;
unsigned int char_cnt = 0;
while(abs_val > 0)
{
buf[char_cnt] = abs_val % 10 + '0';
char_cnt ++;
abs_val = abs_val / 10;
}
if(negative) buf[char_cnt++] = '-';
//reverse the string
unsigned int i = 0;
while(i < char_cnt / 2)
{
char temp = buf[i];
buf[i] = buf[char_cnt-i-1];
buf[char_cnt-i-1] = temp;
i++;
}
buf[char_cnt] = '\0';
}
Ò»Çп´ÆðÀ´¶¼Ã»ÓÐÎÊÌâ¡£µ«ÊÇ£¬Èç¹ûÎÒÃÇÕâÑùµ÷Óøú¯ÊýµÄ»°£¬²Â²Â»áÊä³öʲô£º
char buf[40];
itoa_flawed(1 << 31,buf);
cout<<buf;
ÎÒÃǵõ½µÄÊÇ"-"¡£ÕâÊÇΪʲôÄØ£¿´ó¼ÒÇë×¢ÒâµÚ11ÐдúÂë¡£µ±ÎÒÃÇÇóÒ»¸ºÊýµÄ¾ø¶Ôֵʱ£¬Èç¹û»¹ÊÇÓÃÔÀ´´óСµÄÓзûºÅÀàÐÍʱ£¬¿ÉÄÜ»á²úÉúÒç³ö£¡ÎÒÃÇÖªµÀ£¬intÀàÐÍÖ»Äܱíʾ-231
~ 231
-1
Ö®¼äµÄÊýÖµ¡£Èç¹ûÎÒÃǶÔ-231
Çó¾ø¶ÔÖµ²¢°ÑËü´æ·Åµ½intÀàÐ͵ıäÁ¿ÖУ¬»á·¢ÉúʲôÇé¿ö£¿·ÖÎöµ½ÕâÀ´ó¼Ò¶¼Ó¦¸ÃÇå³þÁË°É£¡
Õâ¸öbugÊǺÜÒþ±ÎµÄ¡£ÎÒÔÚÍøÉÏ¿´µ½µÄ´úÂë»ù±¾É϶¼ºÍÉÏÃæ¸ø³öµÄ²î²»¶à£¬Ã»Óп¼ÂÇÕâ¸ö¿ÉÄܵÄÒç³öÎÊÌâ¡£ÐÞÕýµÄ°ì·¨£¬¾ÍÊÇÓøü´óµÄÀàÐÍÀ´´æ·Å¾ø¶ÔÖµ¡£¹Û²ìµ½¾ø¶ÔÖµÊǷǸºµÄ£¬ÎÒÃÇ¿ÉÒÔÓÃÒ»¸öunsigned int
À´±íʾ¾ø¶ÔÖµ£¬ÕâÑù¾Í²»»áÓÐÎÊÌâÁË¡£
Õâ¸öÌâÄ¿¸øÎÒµÄÆôʾÊÇ£¬ËäÈ»¿´ÆðÀ´¼òµ¥µÄÌâÄ¿£¬Ò²¿ÉÄÜÓкܴóµÄÏÝÚå¡£Èç¹ûÕâÊÇÒ»µÀÃæÊÔÌâµÄ»°£¬¹À¼ÆÍêÈ«×ö¶ÔµÄ²»¶à£¬¿ÉÄÜÒ²°üÀ¨ÏÖ³¡µÄÎÒÔÚÄÚ¡£
Ïà¹ØÎĵµ£º
³£¼ûµÄÄÚ´æ·ÖÅäºÍʹÓôíÎó
1) ÄÚ´æµÄÉêÇëºÍ·ÖÅ䲢ûÓгɹ¦£¬µ«³ÌÐòԱȴʹÓÃÁËËü¡£Ò»Ð©ÐÂÊÖ¾³£»á·¸ÕâÖÖ´íÎó£¬ËûÃDz¢²»»áÁôÒâµ½ÄÚ´æûÓзÖÅä³É¹¦¡£ÅжÏÖ¸ÕëµÄÖµÊÇ·ñΪNULL¿ÉÒÔÓÐЧµØ±ÜÃâÕâÖÖ´íÎó¡£
2) ÄÚ´æµÄ·ÖÅäÒѾ³É¹¦£¬µ«ÊÇȴûÓнøÐгõʼ»¯¾ÍÖ±½ÓʹÓÃËüÁË¡£Ê×ÏÈÊ ......
×î½üÒªÓõ½Ïà¹Ø¼¼Êõ£¬ÏÈÌùÔÚÕ⣬ÓпÕÔÙ·Ò³¡£
±¾ÎÄת×Ô£º
http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4399
http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399/JavaScript-Calls-from-C.htm
http://www.codeproject.com/KB/COM/jscalls.aspx
Introduction
Sometimes, when we are usi ......
1¡¢Xerces-C++ÊÇʲô£¿
Xerces-C++ µÄÇ°ÉíÊÇ IBM µÄ XML4C ÏîÄ¿¡£XML4C ºÍ XML4J ÊÇÁ½¸ö²¢ÁеÄÏîÄ¿£¬¶ø XML4J ÊÇ Xerces-J——Java ʵÏÖ——µÄÇ°Éí¡£IBM ½«ÕâÁ½¸öÏîÄ¿µÄÔ´´úÂëÈÃÓë Apache Èí¼þ»ù½ð»á(Apache Software Foundation)£¬ËûÃǽ«Æä·Ö±ð¸ÄÃûΪ Xerces-C++ º ......
cÓïÑԺ궨ÒåµÄÁ¬½Ó·ûÓÐÄÄЩ
[´ËÎÊÌâµÄÍƼö´ð°¸]
(Ò»)ºê¶¨ÒåÖеÄ## Á¬½Ó·ûÓë# ·û
## Á¬½Ó·ûºÅÓÉÁ½¸ö¾®ºÅ×é³É£¬Æ书ÄÜÊÇÔÚ´ø²ÎÊýµÄºê¶¨ÒåÖн«Á½¸ö×Ó´®(token)Áª½ÓÆðÀ´£¬´Ó¶øÐγÉÒ»¸öеÄ×Ó´®¡£µ«Ëü²»¿ÉÒÔÊǵÚÒ»¸ö»òÕß×îºóÒ»¸ö×Ó´®¡£ËùνµÄ×Ó´®(token)¾ÍÊÇÖ¸±àÒëÆ÷Äܹ»Ê¶±ðµÄ×îСÓï·¨µ¥Ôª¡£¾ßÌåµÄ¶¨ÒåÔÚ±àÒëÔÀíÀïÓÐÏ꾡µÄ ......
—¡ï—ÅàѵÖÜÆÚ£º¹²950ѧʱ 5¸öÔÂ
—¡ï—Åàѵ¸½Ôù£º±£Ö¤Ñ§Ô±ÈËÊÖÒ»»úºÍÒ»Ì×ARM9¿ª·¢°å
—¡ï—ÅàѵÄÚÈÝ£ºÔÚÏîÄ¿¾ÀíµÄ´øÁìÏ£¬Í¨¹ýÍê³É¾ÖÍøµÄÂ齫ÓÎÏ·¡¢My ICQ(ÍøÂçÁÄÌì)ºÍ·¢µç»úÔÚÏß¼à¿Øϵͳ£¬BTÏÂÔØÈí¼þ£¬ÕÆÎÕ»ùÓÚLinuxºÍWindowsƽ̨ϵÄC/C++ÆóÒµ¼¶Ó¦ÓõĿª·¢¼¼ÄÜ£¬ÕÆÎÕ´óÐÍÈí¼þÏî ......