string和int間的類型轉換
int 轉換 string













































string和int間是可以自己寫函數實現類型轉換的,但是string和double就不太方便了,stirng轉換double可以自定義函數實現,但是,double轉換string就需要使用庫函數了,如sprintf
posted on 2006-12-10 13:05 Dain 閱讀(13596) 評論(10) 編輯 收藏 引用 所屬分類: 算法
寫出一個可以工作的程序并不夠
posted on 2006-12-10 13:05 Dain 閱讀(13596) 評論(10) 編輯 收藏 引用 所屬分類: 算法
當然可以阿
還有其他的庫函數也可以的sscanf
@hanson
回復 更多評論
stringstream 也是不錯的東東
:) 回復 更多評論
Implementing itoa function is a popular interview question. Here’s one implementation from SAP.
char *itoa(int value)
{
int count, /* number of characters in string */
i, /* loop control variable */
sign; /* determine if the value is negative */
char *ptr, /* temporary pointer, index into string */
*string, /* return value */
*temp; /* temporary string array */
count = 0;
if ((sign = value) < 0) /* assign value to sign, if negative */
{ /* keep track and invert value */
value = -value;
count++; /* increment count */
}
/* allocate INTSIZE plus 2 bytes (sign and NULL) */
temp = (char *) malloc(INTSIZE + 2);
if (temp == NULL)
{
return(NULL);
}
memset(temp,'\0', INTSIZE + 2);
string = (char *) malloc(INTSIZE + 2);
if (string == NULL)
{
return(NULL);
}
memset(string,'\0', INTSIZE + 2);
ptr = string; /* set temporary ptr to string */
/*--------------------------------------------------------------------+
| NOTE: This process reverses the order of an integer, ie: |
| value = -1234 equates to: char [4321-] |
| Reorder the values using for {} loop below |
+--------------------------------------------------------------------*/
do {
*temp++ = value % 10 + '0'; /* obtain modulus and or with '0' */
count++; /* increment count, track iterations*/
} while (( value /= 10) >0);
if (sign < 0) /* add '-' when sign is negative */
*temp++ = '-';
*temp-- = '\0'; /* ensure null terminated and point */
/* to last char in array */
/*--------------------------------------------------------------------+
| reorder the resulting char *string: |
| temp - points to the last char in the temporary array |
| ptr - points to the first element in the string array |
+--------------------------------------------------------------------*/
for (i = 0; i < count; i++, temp--, ptr++)
{
memcpy(ptr,temp,sizeof(char));
}
return(string);
}
回復 更多評論
http://video-porno-casalinghe.fatte-tun.info
http://xxx-latinas.fatte-tun.info
http://foto-donna-mature-porca.fatte-tun.info
http://video-porno-gay-gratis-cellulare.gradis-tun.info
http://gnocca-sventrate.fatte-tun.info
http://belle-anziane-in-collant.fatte-tun.info
http://transattive-transex.fatte-tun.info
http://lottatrici-erotiche.fatte-tun.info
http://ragazza-giovane-fanno-sesso.fatte-tun.info
http://piace-far-sesso-tovolo-nia-cucino.gradis-tun.info
http://sex-sesso-porno-gay.fatte-tun.info
http://negra-sesso-negra-troia-negra-culo-sborra-pompino.fatte-tun.info
http://immagine-cazzo-enorme-gratis.sculaccia-tun.info
http://culo-donna-formosi.fatte-tun.info
http://coppie-amatoriale.sculaccia-tun.info
http://porno-diciotenni.fatte-tun.info
http://mutandine-igienica-incontinenza.fatte-tun.info
http://gay-twinks-teen-young.gradis-tun.info
http://porno-lesbian-ass-finger-ring-clip-movie.sculaccia-tun.info
http://sexishop-salerno.sculaccia-tun.info
http://erotica-tour-2006.gradis-tun.info
http://sfondami-il-culo.fatte-tun.info
http://sexy-bar-la-tv-piccante.sculaccia-tun.info
http://porno-gay-sado.fatte-tun.info
http://video-sborrata-gay-gratis.fatte-tun.info
http://vecchia-arrapata.fatte-tun.info 回復 更多評論
只有注冊用戶登錄后才能發表評論。 | ||
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
![]() |
||
相關文章:
|
||
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
|
||
|