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

            liyuxia713

            蹣跚前行者

            常用鏈接

            統計

            Algorithms

            C++

            最新評論

            sprintf

            sprintf:  http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
             

            Portotype:  int printf(char* str, const char* format, parameters);

            Writes into the array pointed by str a C string consisting on a sequence of data formatted as the format argument specifies. After the format parameter, the function expects at least as many additional arguments as specified in format.

            This function behaves exactly as printf does, but writing its result to a string instead of stdout. The size of the array passed as str should be enough to contain the entire formatted string .

            Return value:

            On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string.

            //Success
            //The size of str is long enough
            //the number of additional number match with the format
            const int size = 25;
            char *str = new char[size]; 

               //same as int flag1 = sprintf(str,"%s is written to str.","Test","tEST");
            int flag1 = sprintf(str,"%s is written to str.","Test");
            //Console: 23-Test is written to str
            cout << flag1 << "-" << str << endl; 
            On failure, a negative number is returned.
            //Failure1
            //additional arguments numbers is less than specified is format
            //the second %s transmited as unrecognizable words
            const int size = 25;
            char *str = new char[size]; 
            int flag2 = sprintf(str,"%s %s tttttttttttt","Test");
            //Console: 19--Test @ tttttttttttt
            cout << flag2 << "--" << str << endl;

            //Failure2:the size of str is not long enough
               // 在dev c++不能運行,vc6.0沒有問題

            const int size = 25;
            char *str = new char[size]; 
            int flag3 = sprintf(str,"%s jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj","Test");
            //VC6.0 Console: Test jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
            //Dev c++: Console: the same as vc6.0 but throws an cannot read memory exception
            cout << flag3 << "--" << str << endl;

            沒有測試出什么時候出錯返回負值呢?。≌l給我一個例子?

            posted on 2010-04-25 19:23 幸運草 閱讀(494) 評論(0)  編輯 收藏 引用 所屬分類: C++

            久久久无码精品亚洲日韩按摩| 久久精品99无色码中文字幕| 中文字幕久久波多野结衣av| 99久久国产宗和精品1上映| 久久亚洲国产成人精品性色| 国产精品久久久久9999高清| 精品久久久久国产免费| 狠狠色丁香婷婷久久综合五月 | 久久中文娱乐网| 久久激情亚洲精品无码?V| 亚洲愉拍99热成人精品热久久| 久久久综合九色合综国产| 久久亚洲精品无码aⅴ大香| 精品综合久久久久久97超人 | 久久久久久毛片免费看| 久久亚洲AV成人出白浆无码国产| 国产成人精品久久| 国内精品伊人久久久久AV影院| 亚洲伊人久久综合影院| 97精品国产97久久久久久免费| 久久久一本精品99久久精品88 | 无码国内精品久久人妻| 欧美麻豆久久久久久中文| 狠狠干狠狠久久| 久久天天躁狠狠躁夜夜躁2O2O| 香蕉久久夜色精品国产2020 | 一本色道久久88加勒比—综合| 久久棈精品久久久久久噜噜| 亚洲精品无码久久久久久| 亚洲精品视频久久久| 合区精品久久久中文字幕一区| 久久996热精品xxxx| 久久久久国产一区二区三区| 伊人色综合久久| 爱做久久久久久| 久久丝袜精品中文字幕| 国产精品久久久久久久午夜片| 久久99精品国产99久久6| 久久精品女人天堂AV麻| 亚洲午夜无码AV毛片久久| 中文国产成人精品久久亚洲精品AⅤ无码精品|