cstring可以轉換為基本型別lpctstr,lpctstr根據專案編碼可以是const char*或者const wchar_t*;string可以用c_str()轉換為const char*,stringw可以用c_str()轉換為const w_char*。而cstring和string/w都過載了=賦值操作符,可以把char*或者wchar_t*字串賦值給cstring或者string/w型別的變數,或者呼叫其建構函式。
string to cstring比較簡單
string str="abcde";
cstring cstr(str.c_str());
cstring to string,要看你的cstring用的是unicode還是非unicode,
非unicode就簡單了
cstring cs="abcde";
string str(cs.getbuffer(cs.getlength()));
unicode就麻煩點
需要轉換一下才行,給個函式你用
cstring cs=_t("abcde");
string str=cgeneralutility::wchar2ansi(cs.getbuffer(cs.getlength()));
string cutility::wchar2ansi(lpcwstr pwszsrc)
1,string -> cstring
cstring.format("%s", string.c_str());
2,char -> string
string s(char *);
3,cstring -> string
string s(cstring.getbuffer());
getbuffer()後一定要releasebuffer(),否則就沒有釋放緩衝區所佔的空間.
setdlgitemtext(idc_edit1,filename);
sprintf(szport, "com%d", portnr); //ortnr是整形,szport 是char * 型,這個函式的作用就是把字串com與整形連線在一起,然後存在szport字元裡
m_baudstr=atoi(dlg.m_baudstr); //這個函式是把cstring型的同m_baudstr轉化為整型 ,然後存在m_baudstr裡面;
VC 常用資料型別轉化
char 轉換成 lpctstr const char dibfilename int num multibytetowidechar 0,0,dibfilename,1,null,0 wchar t wide new wchar t num multibytetowidechar 0,0,dibf...
資料型別轉化
自己寫的,可能有某些bug,希望大家提出來 函式介紹 進製轉換 函式說明 10進製轉換16進製制 輸入引數 需要轉換的10進製數data 輸出引數 無 int value convert 10 16 int m data return m value 函式介紹 數值轉換 函式說明 對大於10的數進行...
MFC中常用資料型別轉換
剛接觸vc程式設計的朋友往往對許多資料型別的轉換感到迷惑不解,本文將介紹一些常用資料型別的使用。我們先定義一些常見型別變數藉以說明 int i 100 long l 2001 float f 300.2 double d 12345.119 char username 程佩君 char temp 2...