資料儲存型別之間的轉換總結

2021-09-20 08:08:58 字數 2571 閱讀 1204

一、char轉 tchar

char a[124];

tchar b[124];

multibytetowidechar(cp_acp, 0,

a, -1,

b, 128);

二、tchar 轉string

tchar *

str=new tchar[1200];

std::string tchar2string(tchar *

str)

三、string轉tchar

std::string 

m_csfilename

= std::string("hello");  

tchar 

wc[max_path];  

#ifdef unicode  

_stprintf_s(wc, max_path, _t("%s"), 

m_csfilename.c_str()

);//%s寬字元  

#else  

_stprintf_s(wc, max_path, _t("%s"), 

m_csfilename.c_str()

);//%s單字元  

#endif 

四、tchar 轉char

tchar *

str=new tchar[1200];

lpstr

pszout

= null;

int ninputstrlen = wcslen (str);

int noutputstrlen = widechartomultibyte (cp_acp, 0,

str, ninputstrlen, null, 0, 0, 0) + 2;

pszout = new char [noutputstrlen];

memset (pszout, 0x00, noutputstrlen);

widechartomultibyte(cp_acp, 0,

str, ninputstrlen,

pszout

, noutputstrlen, 0, 0);

fprintf(fp,"%s",

pszout);

五、cstring轉tchar*

cstring->tchar*的轉化可以用函式getbuff()

函式原型為:lptstr getbuffer( int nminbuflength );

cstring str("cstring");

tchar* szmsg = new tchar[100];

//其引數為cstring字串的長度

szmsg = str.getbuffer(str.getlength());

str.releasebuffer();

delete szmsg;

szmsg = null;

六、tchar*轉cstring

tchar sztchar[18] = l"tchar";   

cstring  str;   

str.format(_t("%s"),sztchar); 

七、cstring轉char

cstring str=_t("你好");

char ch[4];

for(int i=0;i

例:

char str2[120]=;

for(int i=0;im_customset->strtime1.getlength();i++)

char str3[120]=;

strcpy(str3,mwyf_v_sensor_node[i].name);

char *cat=strcat( str3,str2);

八、cstring 轉char*

cstring filepath = openfiledlg.getpathname();

file *fp;

char *

pnumber

=new char[256];

widechartomultibyte(cp_acp,0,filepath,-1,pnumber,256,null,null );

fp=fopen(pnumber,"w+");

九、char*轉cstring

char *str ="aaaa"   

cstring  str1(str);  

十、int 轉cstring

int i =100;   cstring str;   str.format("%d",i);  //

str.format(

_t("%d")

,i); 

十一、列舉型別轉換為字串

static inline char* weather_str(enum enum_weather w) //列舉型別轉化為char*

Python常用資料型別之間的轉換總結

函式 描述in base 將x轉換為乙個整數 long x base 將x轉換為乙個長整數 float x 將x轉換到乙個浮點數 complex real imag 建立乙個複數 str x 將物件 x 轉換為字串 程式設計客棧 repr x 將物件 x 轉換為表示式字串 eval str 用來計算...

資料型別之間的轉換

parseint 將乙個字串轉換為整數數值。parsefloat 將乙個字串轉換成為浮點小數值。兩個函式都是從字串的開始讀取乙個數字並返回數值。例如下面的語句將 30 angry polar bears 這個字串轉換成數字 stringvar 30 angry polar bears munvar ...

資料型別之間的轉換

一 let console.log true false由於 沒有被賦值,因此console.log 為undefined,會拿undefined與true進行對比,因此會輸出false console.log undefined true而上述就會輸出true 二 let 1 console.lo...