• <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各類型轉換

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

            目錄

               附加(數據庫ADO類型):

            文本

            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)
            文本是一個在代碼中被引號包圍的串,文本它不是一個單純的wxString類型,并且(在wxWidgets 2.8中)不能被隱含的轉換為一個wxString類型。這意味著你不能試圖將光禿禿的將一段文本放到wxWidget函數或方法中通過編譯(除非你不在 意你的應用程序是需要在Unicode編碼環境中通過編譯的)。

            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() 返回一個臨時的指針,如果你需要通過函數得到更多的返回結果(就和上面的情況一樣),你可以臨時保存一下這個字符數據流:

            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 

            當你真的需要將它復制為char*類型時:

            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(), 因為你得到的編碼比用mb_str()函數從const char*轉換成char*更加清楚。

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

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

            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*

            請翻閱官方文檔的以下方法:

            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開始, 你可以用適當的構造函數:

            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, 你可以用這個方法

            wxString::ToStdString()

            std::wstring to wxString

            從wxWidgets 2.9開始, 你可以用適當的構造函數:

            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, 你可以用這個方法

            wxString::ToStdWstring()


            附:(數據庫類型)

            " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">wxString 轉 _bstr_t
             

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

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

            " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">_variant_t 轉 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 轉 _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 多彩人生 閱讀(4415) 評論(1)  編輯 收藏 引用

            評論

            # re: wxWidgets中wxString各類型轉換[未登錄] 2014-01-16 22:30 Zero

            你好,我看到你研究WX很深入的,我們公司開發用的是WX,有沒興趣來我們公司?我們公司在深圳,有興趣的話,可以聯系我:zeroliql@gmail.com
              回復  更多評論   

            導航

            統計

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            99久久综合国产精品二区| 色综合久久久久久久久五月| 久久久久中文字幕| 欧美一区二区精品久久| 久久精品国产一区二区| 午夜天堂av天堂久久久| 久久久精品午夜免费不卡| 久久天天躁狠狠躁夜夜躁2014| 国产精品国色综合久久| 亚洲?V乱码久久精品蜜桃 | 亚洲人成伊人成综合网久久久| 国产精品久久久久影院嫩草| 久久久久九国产精品| 国产精品久久一区二区三区 | 久久精品日日躁夜夜躁欧美| 国产精品一久久香蕉国产线看观看 | 久久影院综合精品| 久久久久久A亚洲欧洲AV冫| 99国产精品久久久久久久成人热| 久久久久国色AV免费看图片| 久久九九有精品国产23百花影院| 久久人人爽人人爽人人片AV麻烦 | 色综合久久久久无码专区| 久久国产三级无码一区二区| 国产精品欧美久久久天天影视| 久久精品人人做人人爽电影| 亚洲国产精品无码久久九九| 97精品国产97久久久久久免费| 久久久一本精品99久久精品88| 久久精品一本到99热免费| 亚洲欧美另类日本久久国产真实乱对白| 久久九九亚洲精品| 中文精品久久久久国产网址| 国产精品久久永久免费| 国内精品久久久久伊人av| 久久偷看各类wc女厕嘘嘘| 久久久久99精品成人片试看 | 久久精品亚洲欧美日韩久久| 国产成人精品久久亚洲高清不卡| 久久久久中文字幕| 国产亚洲成人久久|