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

            蹣跚前行者

            常用鏈接

            統(tǒng)計(jì)

            Algorithms

            C++

            最新評(píng)論

            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++不能運(yùn)行,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;

            沒有測試出什么時(shí)候出錯(cuò)返回負(fù)值呢?。≌l給我一個(gè)例子?

            posted on 2010-04-25 19:23 幸運(yùn)草 閱讀(507) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++

            国产综合久久久久| 一本综合久久国产二区| 久久国产精品成人影院| 精品国产VA久久久久久久冰| 欧美日韩中文字幕久久伊人| 久久这里有精品| 久久精品国产91久久综合麻豆自制 | 久久乐国产精品亚洲综合| 久久久无码精品亚洲日韩蜜臀浪潮| 伊人久久大香线蕉av不卡| 国产激情久久久久影院老熟女| 伊人久久大香线蕉av不变影院| 久久青草国产精品一区| 国产成人综合久久精品红| 国产99久久久国产精免费| 国产精品99久久99久久久| 7777精品伊人久久久大香线蕉| 中文精品久久久久国产网址 | 亚洲国产成人久久综合野外| AAA级久久久精品无码片| 亚洲中文字幕无码久久精品1| 国产精品狼人久久久久影院| 99久久精品国产免看国产一区| 久久久久久精品久久久久| 色综合久久久久综合99| 精品国产热久久久福利| 伊人久久免费视频| 久久精品国产亚洲一区二区| 大伊人青草狠狠久久| 久久天天躁狠狠躁夜夜网站| 18岁日韩内射颜射午夜久久成人 | 久久影视综合亚洲| 久久天天躁狠狠躁夜夜av浪潮| 91精品国产91久久久久久蜜臀| 精品久久久久久久| 久久av免费天堂小草播放| 狠狠色综合久久久久尤物| 久久久久国产视频电影| 精品国产热久久久福利| 伊人久久大香线蕉综合热线| 日本五月天婷久久网站|