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

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

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

            久久久噜噜噜久久中文字幕色伊伊 | 亚洲AV无码久久寂寞少妇| 亚洲精品tv久久久久| 亚洲中文字幕无码久久2017| 久久99热这里只有精品国产| 77777亚洲午夜久久多喷| 激情久久久久久久久久| 久久精品国产AV一区二区三区 | 无夜精品久久久久久| 亚洲国产精品久久久天堂 | 99re久久精品国产首页2020| 香港aa三级久久三级| 久久亚洲国产精品成人AV秋霞| 国产综合久久久久| 一本色道久久88综合日韩精品 | 久久久久亚洲精品日久生情| 91精品国产色综久久| 无码精品久久久久久人妻中字| 国内精品久久久久久久涩爱| 国内精品久久久久影院日本| 久久精品国产免费观看三人同眠| 久久精品国产亚洲AV不卡| 国产精品视频久久久| 久久久久亚洲av综合波多野结衣 | 88久久精品无码一区二区毛片| 久久综合亚洲鲁鲁五月天| 久久久久一本毛久久久| 91久久精品电影| 日本久久久久久中文字幕| 国产成人精品久久免费动漫| 亚洲中文字幕无码一久久区| 欧美伊人久久大香线蕉综合| 亚洲国产高清精品线久久| 国产精品成人99久久久久91gav| 久久亚洲欧美国产精品| 人妻精品久久无码专区精东影业| 久久综合视频网| 综合人妻久久一区二区精品| 久久婷婷国产剧情内射白浆| 99久久精品免费看国产一区二区三区 | 久久久久亚洲av成人无码电影|