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

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲人成网亚洲欧洲无码久久| 99久久精品费精品国产一区二区 | 欧美丰满熟妇BBB久久久| 色欲久久久天天天综合网精品 | 久久国产精品一国产精品金尊| 久久综合香蕉国产蜜臀AV| 91精品国产色综合久久| 国产91色综合久久免费分享| 久久精品不卡| 久久国产精品成人影院| 久久人人爽人人爽人人片AV麻豆| 久久99热只有频精品8| 777午夜精品久久av蜜臀 | 久久综合亚洲色一区二区三区| 久久精品国产影库免费看 | 青青草国产成人久久91网| 久久久这里有精品| 久久久久久国产精品无码下载| 久久精品国产亚洲av麻豆蜜芽| 最新久久免费视频| 久久久高清免费视频| 亚洲综合婷婷久久| 久久WWW免费人成—看片| 国产精品一区二区久久精品无码| 青青草原综合久久| 久久综合久久自在自线精品自| 99久久综合国产精品免费| 日日狠狠久久偷偷色综合96蜜桃| 99久久国产免费福利| 97久久精品午夜一区二区| 亚洲va久久久噜噜噜久久男同 | 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久精品国产亚洲av水果派| 久久久久久午夜精品| 亚洲欧美另类日本久久国产真实乱对白| 一级做a爱片久久毛片| 欧美精品一区二区精品久久| 国产精品久久久久久久| 久久99亚洲网美利坚合众国| 国产美女久久久| 国产精品午夜久久|