• <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东京热| 91精品国产综合久久香蕉| 婷婷国产天堂久久综合五月| 精品久久久久久久无码 | 久久九九亚洲精品| 久久久久se色偷偷亚洲精品av| 久久青草国产手机看片福利盒子| 色综合久久夜色精品国产| 99久久99久久| 亚洲国产美女精品久久久久∴| 婷婷久久综合| 996久久国产精品线观看| 久久久久久久91精品免费观看| 久久综合九色综合久99| 久久超碰97人人做人人爱| 超级碰碰碰碰97久久久久| 国产精品伦理久久久久久| 久久99热狠狠色精品一区| 久久久精品国产sm调教网站 | 久久精品亚洲福利| 国产精品美女久久久久AV福利| 国产Av激情久久无码天堂| 中文字幕日本人妻久久久免费| 亚洲国产精品嫩草影院久久| 久久成人18免费网站| 久久久久久久久久久免费精品| 成人a毛片久久免费播放| 麻豆精品久久精品色综合| 久久97久久97精品免视看秋霞|