• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            colorful

            zc qq:1337220912

             

            wxWidgets中wxString各類(lèi)型轉(zhuǎn)換

            http://www.cnzui.com/archives/290#std::string_to_wxString

            目錄

               附加(數(shù)據(jù)庫(kù)ADO類(lèi)型):

            文本

            A literal is a string written in code with "quotes around it". A literal is not a wxString, and (in wxWidgets 2.8) will not be implicitly converted to one. This means that you can never pass in a raw literal into a wxWidget function or method (unless you don't care about your app not building with Unicode-enabled wxWidgets builds)
            文本是一個(gè)在代碼中被引號(hào)包圍的串,文本它不是一個(gè)單純的wxString類(lèi)型,并且(在wxWidgets 2.8中)不能被隱含的轉(zhuǎn)換為一個(gè)wxString類(lèi)型。這意味著你不能試圖將光禿禿的將一段文本放到wxWidget函數(shù)或方法中通過(guò)編譯(除非你不在 意你的應(yīng)用程序是需要在Unicode編碼環(huán)境中通過(guò)編譯的)。

            MessageBox("I'm a mistake!")  // WRONG in WxWidgets 2.8 (OK in 2.9) 

            Instead, wxWidgets (prior to wxWidgets 2.9) requires you to use one of these macros to turn literals into wxString-compatible characters:

            _("text that can be translated") wxT("text that won't be translated") _T("same as wxT")   char* c = "sometext"; wxT(c) // WRONG, not a literal 

            Rather than being a nuisance, the _(), wxT(), and _T() macros take care of some unicode issues and help with internationalization.

            char* to wxString

            const char* chars = "Hello world"; // assuming your string is encoded as UTF-8, change the wxConv* parameter as needed wxString mystring(chars, wxConvUTF8);

            wxString to char*

            void my_function(const char* foo) { } ... wxString mystring(wxT("HelloWorld")); // you could give the encoding you want as a parameter to mb_str(), e.g. mb_str(wxConvUTF8) my_function( mystring.mb_str() );

            mb_str() 返回一個(gè)臨時(shí)的指針,如果你需要通過(guò)函數(shù)得到更多的返回結(jié)果(就和上面的情況一樣),你可以臨時(shí)保存一下這個(gè)字符數(shù)據(jù)流:

            wxString s( wxT("some string") ); wxCharBuffer buffer=s.ToUTF8(); foo( buffer.data() );  // data() returns const char * bar( buffer.data(), strlen(buffer.data()) );  // in case you need the length of the data 

            當(dāng)你真的需要將它復(fù)制為char*類(lèi)型時(shí):

            wxString mystring(wxT("HelloWorld")); char cstring[1024]; // assuming you want UTF-8, change the wxConv* parameter as needed strncpy(cstring, (const char*)mystring.mb_str(wxConvUTF8), 1023);

            你也可以用ToUTF8(), 因?yàn)槟愕玫降木幋a比用mb_str()函數(shù)從const char*轉(zhuǎn)換成char*更加清楚。

            wxString mystring(wxT("HelloWorld")); (const_cast<char*>((const char*)mystring.mb_str()))

            在可變參數(shù)的函數(shù) (如printf)中用mb_str()函數(shù)將無(wú)效,但按以下的方法是有效的:

            wxString mystring(wxT("HelloWorld")); printf("%s",mystring.mb_str().data());

            做為選擇,使用Potential Unicode Pitfalls中推薦的方法:

            printf("%s", (const char*)mystring.mb_str())

            wchar_t* to wxString

            const wchar_t* chars = L"Hello world"; wxString mystring(chars);

            wxString to wchar_t*

            請(qǐng)翻閱官方文檔的以下方法:

            wxString::wc_str() wxString::wchar_str()

             

            wxString to TCHAR

            TCHAR tCharString[255]; wxString myString(_T("Hello World")); const wxChar* myStringChars = myString.c_str(); for (int i = 0; i < myString.Len(); i++) {    tCharString[i] = myStringChars [i]; } tCharString[myString.Len()] = _T('\0');

            int to wxString

            wxString mystring = wxString::Format(wxT("%i"),myint);

            或者

            wxString mystring; mystring << myint;

            float to wxString

            wxString mystring = wxString::Format(wxT("%f"), myfloat);

            或者

            wxString mystring; mystring << myfloat;

            wxString to integer number

            wxString number(wxT("145")); long value; if(!number.ToLong(&value)) { /* error! */ }

            或者

            wxString str = _T("123"); int num;   num = wxAtoi(str);

            wxString to floating-point number

            wxString number(wxT("3.14159")); double value; if(!number.ToDouble(&value)){ /* error! */ }

            std::string to wxString

            std::string stlstring = "Hello world"; // assuming your string is encoded as UTF-8, change the wxConv* parameter as needed wxString mystring(stlstring.c_str(), wxConvUTF8);

            從wxWidgets 2.9開(kāi)始, 你可以用適當(dāng)?shù)臉?gòu)造函數(shù):

            std::string stlstring = "Hello world"; // assuming your string is encoded as the current locale encoding (wxConvLibc) wxString mystring(stlstring);

            wxString to std::string

            在wxWidgets 2.8 :

            wxString mystring(wxT("HelloWorld")); std::string stlstring = std::string(mystring.mb_str());

            在wxWidgets 2.9, 你可以用這個(gè)方法

            wxString::ToStdString()

            std::wstring to wxString

            從wxWidgets 2.9開(kāi)始, 你可以用適當(dāng)?shù)臉?gòu)造函數(shù):

            std::sstring stlstring = L"Hello world"; // assuming your string is encoded as the current locale encoding (wxConvLibc) wxString mystring(stlstring);

            wxString to std::wstring

            在wxWidgets 2.9, 你可以用這個(gè)方法

            wxString::ToStdWstring()


            附:(數(shù)據(jù)庫(kù)類(lèi)型)

            " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">wxString 轉(zhuǎn) _bstr_t
             

            wxString str(wxT("Hello")); _bstr_t mystring=_bstr_t(str.wc_str()); 

            " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">_bstr_ 轉(zhuǎn) wxString
            _bstr_t bstr="hello"; wxString mystring = wxString(static_cast<const wchar_t *>(bstr)); 

            " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">_variant_t 轉(zhuǎn) wxString

            _variant_t  varstr=_variant_t("Hello"); wxString mystring=wxString(static_cast<const wchar_t *>(_bstr_t(varstr))); 

            " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">wxString 轉(zhuǎn) _variant_t

            wxString str(wxT("Hello")); _variant_t myvar=_variant_t(str.wc_str()); 

             

            本文翻譯自wxWidgets官方:http://wiki.wxwidgets.org/Converting_everything_to_and_from_wxString

            posted on 2013-08-10 09:29 多彩人生 閱讀(4479) 評(píng)論(1)  編輯 收藏 引用

            評(píng)論

            # re: wxWidgets中wxString各類(lèi)型轉(zhuǎn)換[未登錄](méi) 2014-01-16 22:30 Zero

            你好,我看到你研究WX很深入的,我們公司開(kāi)發(fā)用的是WX,有沒(méi)興趣來(lái)我們公司?我們公司在深圳,有興趣的話(huà),可以聯(lián)系我:zeroliql@gmail.com
              回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(3)

            隨筆分類(lèi)

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            日本欧美久久久久免费播放网| 久久免费视频观看| 久久婷婷五月综合国产尤物app| 噜噜噜色噜噜噜久久| 中文字幕日本人妻久久久免费| 国产成人精品白浆久久69| 精品国产91久久久久久久a| 思思久久好好热精品国产| 九九久久自然熟的香蕉图片| 久久久久国产一区二区| 久久精品99久久香蕉国产色戒| 久久精品免费一区二区三区| 婷婷久久五月天| 国产高清国内精品福利99久久| 一本色道久久综合亚洲精品| 国产69精品久久久久9999| 乱亲女H秽乱长久久久| 午夜精品久久久内射近拍高清| 国产精品女同久久久久电影院| 久久久久久噜噜精品免费直播| 日产精品久久久久久久性色| 思思久久99热免费精品6| 亚洲一本综合久久| 国产精品美女久久久久网| 久久伊人精品一区二区三区| 狠狠人妻久久久久久综合| 久久91综合国产91久久精品| 模特私拍国产精品久久| 亚洲成av人片不卡无码久久| 99久久精品这里只有精品| 国产精品18久久久久久vr | 9久久9久久精品| 久久亚洲春色中文字幕久久久| 热综合一本伊人久久精品| 日批日出水久久亚洲精品tv| 国产无套内射久久久国产| 天天久久狠狠色综合| 伊人色综合久久天天| 国产精品成人99久久久久91gav| 色综合久久久久网| 开心久久婷婷综合中文字幕|