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

            不戒廟

            求助:CString Format自身的溢出的問題

            以下是代碼

            1 CString strMsg1 = "確認要刪除 %s 嗎?";
            2 CString title = "標題";
            3 StrMsg1.Format(strMsg1,title");
            以上這段代碼出錯
            Expression:("Buffer too small",0)

            而換成

            1 CString strMsg1 ;
            2 CString title = "標題";
            3 StrMsg1.Format("確認要刪除 %s 嗎?",title");
            就不出錯了

            環境:Win2k3_En_Sp2 + VS2005

            各位達人,能告訴我是什么原因。

            posted on 2008-07-19 11:07 不戒大師 閱讀(3744) 評論(9)  編輯 收藏 引用

            Feedback

            # re: 求助:CString Format自身的溢出的問題 2008-07-19 11:35 斯卡

            不明白你的title后為什么要加"  回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題 2008-07-19 12:06 三不戒大師

            title值是變量啊,并不是固定值
              回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題[未登錄] 2008-07-19 12:15 Kevin

            title 不是字符串對象, 而不是char指針, 你應該 (LPCSTR)title 才對, 因為CString重載了LPCSTR, 這樣在運行時才能自動轉換成char指針, 匹配到 %s  回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題[未登錄] 2008-07-19 12:16 Kevin

            改一下"title 不是字符串對象" 應為 "title是CString對象"  回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題 2008-07-19 12:40 陳梓瀚(vczh)

            CString能隱式轉換到LPCTSTR的,這個倒不是問題。難道CString非空的時候,Format就默認『該對象被重新利用,而不是重新構造一個新的CString對象』?  回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題 2008-07-19 12:54 wxyz

            CString::Format
            void Format( LPCTSTR lpszFormat, ... );

            void Format( UINT nFormatID, ... );

            Parameters

            lpszFormat

            A format-control string.

            nFormatID

            The string resource identifier that contains the format-control string.

            Remarks

            Call this member function to write formatted data to a CString in the same way that sprintf formats data into a C-style character array. This function formats and stores a series of characters and values in the CString. Each optional argument (if any) is converted and output according to the corresponding format specification in lpszFormat or from the string resource identified by nFormatID.
            ////!!!!!這地方好像說了.
            The call will fail if the string object itself is offered as a parameter to Format. For example, the following code:

            CString str = "Some Data";
            str.Format("%s%d", str, 123); // Attention: str is also used in the parameter list.

            will cause unpredictable results.
            ////!!!!
            When you pass a character string as an optional argument, you must cast it explicitly as LPCTSTR. The format has the same form and function as the format argument for the printf function. (For a description of the format and arguments, seeprintf in the Run-Time Library Reference.) A null character is appended to the end of the characters written.

              回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題 2008-07-19 16:01 三不戒大師

            @wxyz
            謝謝,終于弄明白是怎么回事了  回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題 2008-07-19 17:01 陳梓瀚(vczh)

            經常看到msdn里面把bug當成feature……  回復  更多評論   

            # re: 求助:CString Format自身的溢出的問題[未登錄] 2008-07-20 08:55 Leo

            @陳梓瀚(vczh)
            這本來就是一種未定義情況,如同snprintf中將自己作為一個參數一樣…  回復  更多評論   


            My Links

            Blog Stats

            常用鏈接

            留言簿

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久精品久久久久特色影视| 人妻精品久久无码区| 久久本道久久综合伊人| 久久亚洲国产成人精品无码区| 亚洲精品乱码久久久久久蜜桃| 久久影院综合精品| 久久精品无码专区免费 | 国内精品久久久久久久亚洲| 人妻精品久久久久中文字幕| 久久精品国产精品亚洲毛片| 久久综合综合久久97色| 狠狠色婷婷久久综合频道日韩 | 一本一本久久a久久综合精品蜜桃| 国产韩国精品一区二区三区久久| 久久精品亚洲乱码伦伦中文| 国产精品美女久久久m| 久久久久久国产a免费观看黄色大片 | 国产免费久久久久久无码| 久久人妻少妇嫩草AV蜜桃| 9999国产精品欧美久久久久久| 无码国内精品久久人妻蜜桃 | 色综合久久久久无码专区| 国产精品九九久久免费视频 | 色欲久久久天天天综合网精品| 日日狠狠久久偷偷色综合96蜜桃| 久久久久久久综合日本亚洲 | 人妻少妇精品久久| 91精品国产综合久久四虎久久无码一级 | 国产精品岛国久久久久| 日韩人妻无码精品久久久不卡| 亚洲国产精品一区二区三区久久 | 亚洲午夜无码AV毛片久久| 国产A级毛片久久久精品毛片| 狠狠狠色丁香婷婷综合久久五月 | 香蕉aa三级久久毛片| 久久久免费观成人影院| 久久艹国产| 一级做a爰片久久毛片免费陪| 性欧美大战久久久久久久| 亚洲AⅤ优女AV综合久久久| 亚洲人成网站999久久久综合|