• <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>

            Codejie's C++ Space

            Using C++

            How to convert string to wstring?

                 來源:http://www.codeguru.com/forum/archive/index.php/t-193852.html

            The copy() function does not automatically make room for the destination, so you must make sure that you have enough room in the wstring.

            Why not just write a function to 
            do the conversion?

            #include 
            <string>
            #include 
            <algorithm>

            // Prototype for conversion functions
            std::wstring StringToWString(const std::string& s);
            std::
            string WStringToString(const std::wstring& s);

            std::wstring StringToWString(
            const std::string& s)
            {
            std::wstring temp(s.length(),L
            ' ');
            std::copy(s.begin(), s.end(), temp.begin());
            return temp;
            }


            std::
            string WStringToString(const std::wstring& s)
            {
            std::
            string temp(s.length(), ' ');
            std::copy(s.begin(), s.end(), temp.begin());
            return temp;
            }

            using namespace std;

            int main()
            {
            string s1 = "Hello";
            wstring s2 
            = StringToWString(s1);
            s1 
            = WStringToString(s2);
            return 0;
            }

            Regards,

            Paul McKenzie

            posted on 2009-03-27 12:35 codejie 閱讀(1643) 評論(6)  編輯 收藏 引用 所屬分類: Resource

            評論

            # re: How to convert string to wstring? 2009-03-27 13:03 陳梓瀚(vczh)

            你試試漢字。  回復(fù)  更多評論   

            # re: How to convert string to wstring? 2009-03-27 17:56 codejie

            么問題。  回復(fù)  更多評論   

            # re: How to convert string to wstring? 2009-03-27 22:59 陳梓瀚(vczh)

            你如何判斷他沒事  回復(fù)  更多評論   

            # re: How to convert string to wstring?[未登錄] 2009-03-29 23:03 codejie

            可以正常讀取一個中文文件名的MP3文件。你有什么疑問嗎?  回復(fù)  更多評論   

            # re: How to convert string to wstring?[未登錄] 2013-11-26 01:19 煙圈

            int main()
            {
            //string s1 = "";
            //wstring s2 = StringToWString(s1);
            string s1 = WStringToString(L"中國");

            cout <<s1 <<endl;
            return 0;
            }

            試試肯定不行。。

              回復(fù)  更多評論   

            # re: How to convert string to wstring? 2013-11-26 09:24 codejie

            @煙圈
            會不會是'cout'用的不對呢?  回復(fù)  更多評論   

            公告

            Using C++

            導(dǎo)航

            統(tǒng)計

            留言簿(73)

            隨筆分類(513)

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            成人妇女免费播放久久久| 精品久久久久中文字幕一区| 久久精品国产色蜜蜜麻豆| 77777亚洲午夜久久多喷| 久久丫精品国产亚洲av| 日韩精品久久久久久| 精品国产乱码久久久久久人妻| 精品久久久噜噜噜久久久| 久久久久亚洲AV无码专区网站| 国产成人精品综合久久久久| 91麻精品国产91久久久久| 狠狠色狠狠色综合久久| 国产毛片久久久久久国产毛片| 免费久久人人爽人人爽av| 久久亚洲国产中v天仙www| 久久人人爽人人爽人人av东京热| 国产99久久久国产精品~~牛| 伊人久久无码中文字幕| 亚洲国产综合久久天堂 | 久久水蜜桃亚洲av无码精品麻豆| 国产伊人久久| 久久99精品久久久久久久久久| 亚洲国产成人久久综合碰| 久久综合九色综合久99 | 久久精品国产一区二区三区不卡| 伊人色综合久久天天人手人婷| 人人狠狠综合久久亚洲| 99久久伊人精品综合观看| 91精品国产综合久久精品| 浪潮AV色综合久久天堂| 精品国产青草久久久久福利| 久久久久黑人强伦姧人妻| 久久精品无码一区二区三区免费| 久久91精品久久91综合| 久久久久久国产精品免费无码| 亚洲精品无码久久久久sm| 亚洲国产欧美国产综合久久| 亚洲精品国产字幕久久不卡| 亚洲中文字幕无码久久综合网 | 成人国内精品久久久久影院| 久久亚洲精品人成综合网|