數學型別變數與字串相互轉換(這些函式都在stdlib.h裡)
(1)將數學型別轉換為字串可以用以下一些函式:
舉例: _crtimp char * __cdecl _itoa(int, char *, int);//這是乙個將數字轉換為乙個字串型別的函式,最後乙個int表示轉換的進製
如以下程式:
int ityep=3;
char *szchar;
itoa(itype,szchar,2);
cout《類似函式列表:
_crtimp char * __cdecl _itoa(int, char *, int);//為了完整性,也列在其中
_crtimp char * __cdecl _ultoa(unsigned long, char *, int);
_crtimp char * __cdecl _ltoa(long, char *, int);
_crtimp char * __cdecl _i64toa(__int64, char *, int);
_crtimp char * __cdecl _ui64toa(unsigned __int64, char *, int);
_crtimp wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
_crtimp wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
_crtimp wchar_t * __cdecl _itow (int, wchar_t *, int);//轉換為長字串型別
_crtimp wchar_t * __cdecl _ltow (long, wchar_t *, int);
_crtimp wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
還有很多,請自行研究
(2)將字串型別轉換為數學型別變數可以用以下一些函式:
舉例: _crtimp int __cdecl atoi(const char *);//引數一看就很明了
char *szchar=」88」;
int temp(0);
temp=atoi(szchar);
cout《類似的函式列表:
_crtimp int __cdecl atoi(const char *);
_crtimp double __cdecl atof(const char *);
_crtimp long __cdecl atol(const char *);
_crtimp long double __cdecl _atold(const char *);
_crtimp __int64 __cdecl _atoi64(const char *);
_crtimp double __cdecl strtod(const char *, char **);//
_crtimp long __cdecl strtol(const char *, char **, int);//
_crtimp long double __cdecl _strtold(const char *, char **);
_crtimp unsigned long __cdecl strtoul(const char *, char **, int);
_crtimp double __cdecl wcstod(const wchar_t *, wchar_t **);//長字串型別轉換為數學型別
_crtimp long __cdecl wcstol(const wchar_t *, wchar_t **, int);
_crtimp unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
_crtimp int __cdecl _wtoi(const wchar_t *);
_crtimp long __cdecl _wtol(const wchar_t *);
_crtimp __int64 __cdecl _wtoi64(const wchar_t *);
還有很多,請自行研究
QT列舉型別與字串型別相互轉換
qt5以後 具體版本可能是5.10吧,這個不確定 採用以下方法 在qt中將列舉型別註冊 qt q enum或qt q flag 後,就可以利用qt的元物件進行列舉型別與字串型別轉換了。示例 include intmain 在qss中我們可以這樣使用列舉型別 qtabbar customtabbar ...
QT列舉型別與字串型別相互轉換
qt5以後 具體版本可能是5.10吧,這個不確定 採用以下方法 在qt中將列舉型別註冊 qt q enum或qt q flag 後,就可以利用qt的元物件進行列舉型別與字串型別轉換了。示例 include intmain 在qss中我們可以這樣使用列舉型別 qtabbar customtabbar ...
Python list str型別相互轉換
1 str list s 12345 l list s 結果 1 2 3 4 5 2 list str l 1 2 3 s join l 結果 123 如果list裡的元素是int型而非str型則比較麻煩,還這樣寫會報錯,而在刷題時經常碰到需要將int型的list輸出為str的情況,於是補充以下兩種...