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

                 來(lái)源: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 閱讀(1636) 評(píng)論(6)  編輯 收藏 引用 所屬分類(lèi): Resource

            評(píng)論

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

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

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

            么問(wèn)題。  回復(fù)  更多評(píng)論   

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

            你如何判斷他沒(méi)事  回復(fù)  更多評(píng)論   

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

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

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

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

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

            試試肯定不行。。

              回復(fù)  更多評(píng)論   

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

            @煙圈
            會(huì)不會(huì)是'cout'用的不對(duì)呢?  回復(fù)  更多評(píng)論   

            公告

            Using C++

            導(dǎo)航

            統(tǒng)計(jì)

            留言簿(73)

            隨筆分類(lèi)(513)

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            99久久精品免费观看国产| 中文字幕亚洲综合久久2| 久久国产精品无| 久久精品国产久精国产一老狼| 亚洲精品乱码久久久久久| 精品熟女少妇a∨免费久久| 久久青青草原精品影院| 久久国产免费| 久久亚洲精品中文字幕| 88久久精品无码一区二区毛片| 久久久久国产精品人妻| 久久r热这里有精品视频| 伊人久久成人成综合网222| 97久久久精品综合88久久| 久久人妻少妇嫩草AV蜜桃| 国产三级久久久精品麻豆三级 | 日韩精品久久无码人妻中文字幕| 久久久久久亚洲Av无码精品专口| 久久97久久97精品免视看| 东方aⅴ免费观看久久av| 国产精品伊人久久伊人电影| 国内精品伊人久久久久777| 久久久中文字幕| 亚洲熟妇无码另类久久久| 久久国产免费直播| 91亚洲国产成人久久精品| 久久精品国产久精国产思思| 亚洲国产精品狼友中文久久久| 久久国产精品久久| 国产精品一久久香蕉国产线看| 久久精品免费全国观看国产| 久久精品国产99久久香蕉| 99久久人人爽亚洲精品美女| A狠狠久久蜜臀婷色中文网| 欧美牲交A欧牲交aⅴ久久| 免费久久人人爽人人爽av| 亚洲欧美国产精品专区久久| 欧美成人免费观看久久| 亚洲伊人久久成综合人影院| 久久精品亚洲精品国产欧美| 久久精品无码一区二区三区日韩|