字符数据类型转换代码
生活随笔
收集整理的這篇文章主要介紹了
字符数据类型转换代码
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
《字符數(shù)據(jù)類型轉(zhuǎn)換代碼(全部調(diào)試通過)》
作者:Coderui??????????????????????????????????????????????????????????? 書于:2007-6-12
------------------------------------------------------------------------
int nSize;
char* bufw;
CString str = "Coderui"; nSize = str.GetLength();
bufw = new char[nSize + 1];
strcpy (bufw, str);//CString轉(zhuǎn)char* delete[] bufw;
------------------------------------------------------------------------
CString str = "Coderui";
char* p;
p = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)char*
------------------------------------------------------------------------
CString str = "Coderui";
unsigned char* p;
p = (unsigned char*)str.GetBuffer(str.GetLength());//CString轉(zhuǎn)unsigned char*
------------------------------------------------------------------------
CString str = "88";
int i = atoi(str);//CString轉(zhuǎn)int
------------------------------------------------------------------------
char* p = "88";
int i = atoi(p);//char*轉(zhuǎn)int
------------------------------------------------------------------------
int i = 88;
CString str;
str.Format("%d", i);//int轉(zhuǎn)CString
------------------------------------------------------------------------
char ch[8] = {0};
CString str = "Coderui";
strncpy(ch, (LPCTSTR)str, sizeof(ch));//CString轉(zhuǎn)char []
------------------------------------------------------------------------
char ch[8] = {"Coderui"};
CString str;
str.Format(ch);//char []轉(zhuǎn)CString
------------------------------------------------------------------------
CTime Time = GetCurrentTime();
OnTime = Time.Format("%Y-%m-%d %H:%M:%S");//CTime轉(zhuǎn)CString
------------------------------------------------------------------------
CString OnTime;
SYSTEMTIME st; GetLocalTime(&st);
OnTime.Format("%d-%02d-%02d %d:%d:%d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);//SYSTEMTIME轉(zhuǎn)CString(日期)
------------------------------------------------------------------------
CONST CHAR *pc = "Coderui";
CString str;
PCTSTR pctstr;
LPCTSTR lpctstr;
PCUTSTR pcutstr;
LPCUTSTR lpcutstr;
LPCSTR lpcstr;
PCSTR pcstr; str.Format("%s", pc);//CONST CHAR *轉(zhuǎn)CString
pctstr = pc;//CONST CHAR *轉(zhuǎn)PCTSTR
lpctstr = pc;//CONST CHAR *轉(zhuǎn)LPCTSTR
pcutstr = pc;//CONST CHAR *轉(zhuǎn)PCUTSTR
lpcutstr = pc;//CONST CHAR *轉(zhuǎn)LPCUTSTR
lpcstr = pc;//CONST CHAR *轉(zhuǎn)LPCSTR
pcstr = pc;//CONST CHAR *轉(zhuǎn)PCSTR
------------------------------------------------------------------------
CString str = "Coderui"; CONST CHAR *pc;
PCTSTR pctstr;
LPCTSTR lpctstr;
PCUTSTR pcutstr;
LPCUTSTR lpcutstr; LPCSTR lpcstr;
PCSTR pcstr; pc = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)CONST CHAR *
pctstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)PCTSTR
lpctstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)LPCTSTR
pcutstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)PCUTSTR
lpcutstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)LPCUTSTR
lpcstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)LPCSTR
pcstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)PCSTR
------------------------------------------------------------------------
PCTSTR pctstr = "Coderui";
LPCTSTR lpctstr = "Coderui";
PCUTSTR pcutstr = "Coderui";
LPCUTSTR lpcutstr = "Coderui";
LPCSTR lpcstr = "Coderui";
PCSTR pcstr = "Coderui"; CONST CHAR *pc;
CString str; pc = pctstr;//PCTSTR轉(zhuǎn)CONST CHAR *
pc = lpctstr;//LPCTSTR轉(zhuǎn)CONST CHAR *
pc = pcutstr;//PCUTSTR轉(zhuǎn)CONST CHAR *
pc = lpcutstr;//LPCUTSTR轉(zhuǎn)CONST CHAR *
pc = lpcstr;//LPCSTR轉(zhuǎn)CONST CHAR *
pc = pcstr;//PCSTR轉(zhuǎn)CONST CHAR *
str.Format("%s", pctstr);//PCTSTR轉(zhuǎn)CString
str.Format("%s", lpctstr);//LPCTSTR轉(zhuǎn)CString
str.Format("%s", pcutstr);//PCUTSTR轉(zhuǎn)CString
str.Format("%s", lpcutstr);//LPCUTSTR轉(zhuǎn)CString
str.Format("%s", lpcstr);//LPCSTR轉(zhuǎn)CString
str.Format("%s", pcstr);//PCSTR轉(zhuǎn)CString
------------------------------------------------------------------------
int nSize;
char* bufw;
CString str = "Coderui"; nSize = str.GetLength();
bufw = new char[nSize + 1];
strcpy (bufw, str);//CString轉(zhuǎn)char* delete[] bufw;
------------------------------------------------------------------------
CString str = "Coderui";
char* p;
p = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)char*
------------------------------------------------------------------------
CString str = "Coderui";
unsigned char* p;
p = (unsigned char*)str.GetBuffer(str.GetLength());//CString轉(zhuǎn)unsigned char*
------------------------------------------------------------------------
CString str = "88";
int i = atoi(str);//CString轉(zhuǎn)int
------------------------------------------------------------------------
char* p = "88";
int i = atoi(p);//char*轉(zhuǎn)int
------------------------------------------------------------------------
int i = 88;
CString str;
str.Format("%d", i);//int轉(zhuǎn)CString
------------------------------------------------------------------------
char ch[8] = {0};
CString str = "Coderui";
strncpy(ch, (LPCTSTR)str, sizeof(ch));//CString轉(zhuǎn)char []
------------------------------------------------------------------------
char ch[8] = {"Coderui"};
CString str;
str.Format(ch);//char []轉(zhuǎn)CString
------------------------------------------------------------------------
int Year,Month,Day,Hour,Min,Sec;
CString OnTime = "2007-5-8 09:05:21";
sscanf(OnTime, "%d-%d-%d %d:%d:%d", &Year, &Month, &Day, &Hour, &Min, &Sec);
CTime Time(Year, Month , Day, Hour, Min, Sec);//CString轉(zhuǎn)CTime
------------------------------------------------------------------------
CTime Time = GetCurrentTime();
OnTime = Time.Format("%Y-%m-%d %H:%M:%S");//CTime轉(zhuǎn)CString
------------------------------------------------------------------------
CString OnTime;
SYSTEMTIME st; GetLocalTime(&st);
OnTime.Format("%d-%02d-%02d %d:%d:%d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);//SYSTEMTIME轉(zhuǎn)CString(日期)
------------------------------------------------------------------------
CONST CHAR *pc = "Coderui";
CString str;
PCTSTR pctstr;
LPCTSTR lpctstr;
PCUTSTR pcutstr;
LPCUTSTR lpcutstr;
LPCSTR lpcstr;
PCSTR pcstr; str.Format("%s", pc);//CONST CHAR *轉(zhuǎn)CString
pctstr = pc;//CONST CHAR *轉(zhuǎn)PCTSTR
lpctstr = pc;//CONST CHAR *轉(zhuǎn)LPCTSTR
pcutstr = pc;//CONST CHAR *轉(zhuǎn)PCUTSTR
lpcutstr = pc;//CONST CHAR *轉(zhuǎn)LPCUTSTR
lpcstr = pc;//CONST CHAR *轉(zhuǎn)LPCSTR
pcstr = pc;//CONST CHAR *轉(zhuǎn)PCSTR
------------------------------------------------------------------------
CString str = "Coderui"; CONST CHAR *pc;
PCTSTR pctstr;
LPCTSTR lpctstr;
PCUTSTR pcutstr;
LPCUTSTR lpcutstr; LPCSTR lpcstr;
PCSTR pcstr; pc = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)CONST CHAR *
pctstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)PCTSTR
lpctstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)LPCTSTR
pcutstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)PCUTSTR
lpcutstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)LPCUTSTR
lpcstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)LPCSTR
pcstr = str.GetBuffer(str.GetLength());//CString轉(zhuǎn)PCSTR
------------------------------------------------------------------------
PCTSTR pctstr = "Coderui";
LPCTSTR lpctstr = "Coderui";
PCUTSTR pcutstr = "Coderui";
LPCUTSTR lpcutstr = "Coderui";
LPCSTR lpcstr = "Coderui";
PCSTR pcstr = "Coderui"; CONST CHAR *pc;
CString str; pc = pctstr;//PCTSTR轉(zhuǎn)CONST CHAR *
pc = lpctstr;//LPCTSTR轉(zhuǎn)CONST CHAR *
pc = pcutstr;//PCUTSTR轉(zhuǎn)CONST CHAR *
pc = lpcutstr;//LPCUTSTR轉(zhuǎn)CONST CHAR *
pc = lpcstr;//LPCSTR轉(zhuǎn)CONST CHAR *
pc = pcstr;//PCSTR轉(zhuǎn)CONST CHAR *
str.Format("%s", pctstr);//PCTSTR轉(zhuǎn)CString
str.Format("%s", lpctstr);//LPCTSTR轉(zhuǎn)CString
str.Format("%s", pcutstr);//PCUTSTR轉(zhuǎn)CString
str.Format("%s", lpcutstr);//LPCUTSTR轉(zhuǎn)CString
str.Format("%s", lpcstr);//LPCSTR轉(zhuǎn)CString
str.Format("%s", pcstr);//PCSTR轉(zhuǎn)CString
------------------------------------------------------------------------
總結(jié)
以上是生活随笔為你收集整理的字符数据类型转换代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 栈溢出的经典代码
- 下一篇: ntdll.dll和ntoskrnl.e