• <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 幸運草 閱讀(481) 評論(0)  編輯 收藏 引用 所屬分類: C++

            日本道色综合久久影院| 亚洲国产成人久久精品动漫| 狠狠色丁香久久婷婷综合五月| 午夜精品久久久久| 国产精品美女久久福利网站| 久久国产三级无码一区二区| 久久久久久狠狠丁香| 久久综合久久久| 久久99精品久久久久久齐齐| 久久久WWW成人免费精品| 久久精品国产WWW456C0M| 久久www免费人成精品香蕉| 久久国产精品二国产精品 | 久久久精品午夜免费不卡| 国产精品国色综合久久| 久久精品国内一区二区三区| 一本久久a久久精品综合夜夜| 人人狠狠综合久久亚洲婷婷| 久久久久亚洲AV成人网| 亚洲国产成人精品女人久久久 | 欧美久久天天综合香蕉伊| 亚洲&#228;v永久无码精品天堂久久 | 91久久精品视频| 精品久久久久久无码不卡| 麻豆一区二区99久久久久| 伊人久久免费视频| 亚洲欧美成人久久综合中文网 | 国产精品九九久久免费视频 | 久久久这里有精品| 久久久久久久亚洲Av无码| 国产精品日韩欧美久久综合| 麻豆精品久久久久久久99蜜桃| 潮喷大喷水系列无码久久精品| 品成人欧美大片久久国产欧美...| 青青草国产97免久久费观看| 久久综合给合久久狠狠狠97色69 | 亚洲国产成人久久精品影视| 精品国产乱码久久久久久呢| 97久久精品人人做人人爽| 无码人妻久久一区二区三区免费 | 日产精品99久久久久久|