日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 芯聞號(hào) > 充電吧
[導(dǎo)讀]Stephen Liu在C語(yǔ)言編程中,我們不可避免的要接觸到可變參數(shù)函數(shù),對(duì)于不支持函數(shù)多態(tài)的C語(yǔ)言來(lái)講,使用可變參數(shù)和宏定義函數(shù)是變通的實(shí)現(xiàn)函數(shù)多態(tài)的好方法。在進(jìn)一步涉及到可變參數(shù)函數(shù)之前,我們先來(lái)

Stephen Liu

在C語(yǔ)言編程中,我們不可避免的要接觸到可變參數(shù)函數(shù),對(duì)于不支持函數(shù)多態(tài)的C語(yǔ)言來(lái)講,使用可變參數(shù)和宏定義函數(shù)是變通的實(shí)現(xiàn)函數(shù)多態(tài)的好方法。在進(jìn)一步涉及到可變參數(shù)函數(shù)之前,我們先來(lái)看看常用到的兩個(gè)可變參數(shù)的典型,分別是vsprintf和sprintf。

一、vsprintf函數(shù)

Header File

stdio.h

Category

Memory and String Manipulation Routines

Prototype

int vsprintf(char *buffer, const char *format, va_list arglist);

int vswprintf(wchar_t *buffer, const wchar_t *format, va_list arglist);

Description

Writes formatted output to a string.

The v...printf functions are known as alternate entry points for the ...printf functions. They behave exactly like their ...printf counterparts, but they accept a pointer to a list of arguments instead of an argument list.

vsprintf accepts a pointer to a series of arguments, applies to each a format specifier contained in the format string pointed to by format, and outputs the formatted data to a string. There must be the same number of format specifiers as arguments.

Return Value

vsprintf returns the number of bytes output. In the event of error, vsprintf returns EOF.

--對(duì)照翻譯

頭文件
stdio.h

分類(lèi)
內(nèi)存和字符串操作

函數(shù)原型
int vsprintf(char *buffer, const char *format, va_list arglist);

int vswprintf(wchar_t *buffer, const wchar_t *format, va_list arglist);

描述
寫(xiě)格式化后的輸出到一個(gè)字符串

v..printf函數(shù)族是..print函數(shù)族的可替代函數(shù),他們像..printf函數(shù)族一樣操作,但是他們接受指向參數(shù)列表的指針而不是參數(shù)列表。
vsprintf接受一個(gè)指向一系列可變參數(shù)的指針,提供給每一個(gè)參數(shù)一個(gè)包含在form中的格式化定義,并且輸出格式化后的數(shù)據(jù)到一個(gè)字符串中,格式定義和參數(shù)數(shù)量必須相等。

返回值
vsprintf返回輸出的字節(jié)數(shù)目,出錯(cuò)時(shí)返回EOF

二、sprintf函數(shù)

Header File

stdio.h

Category

Memory and String Manipulation Routines

Prototype

int sprintf(char *buffer, const char *format[, argument, ...]);

int swprintf(wchar_t *buffer, const wchar_t *format[, argument, ...]);

Description

Writes formatted output to a string.

Note:?For details on format specifiers, see printf.

sprintf accepts a series of arguments, applies to each a format specifier contained in the format string pointed to by format, and outputs the formatted data to a string.

sprintf applies the first format specifier to the first argument, the second to the second, and so on. There must be the same number of format specifiers as arguments.

Return Value

On success, sprintf returns the number of bytes output. The return value does not include the terminating null byte in the count.

On error, sprintf returns EOF.

--對(duì)照翻譯

頭文件:

stdio.h

頭文件
stdio.h

分類(lèi)
內(nèi)存和字符串操作

函數(shù)原型
int sprintf(char *buffer, const char *format[, argument, ...]);

int swprintf(wchar_t *buffer, const wchar_t *format[, argument, ...]);

描述
寫(xiě)格式化后的輸出到一個(gè)字符串
注意:對(duì)于格式化定義規(guī)范,參看printf
sprintf接受一系列參數(shù),提供給每一個(gè)參數(shù)一個(gè)格式化定義,并且輸出格式化數(shù)據(jù)到字符串
sprintf提供給首個(gè)參數(shù)第一個(gè)格式化定義,第二個(gè)賦予次個(gè)格式化定義,格式化定義數(shù)量必須和參數(shù)數(shù)量一致

返回值
成功,返回輸出的字節(jié)數(shù)量,返回值不包含終止null字節(jié)的字節(jié)數(shù)量
錯(cuò)誤,返回EOF

?

為了便于比較這兩個(gè)函數(shù)的使用,下面給出一個(gè)程序片段:

??? char szBuffer[256];
??? sprintf(szBuffer, "welcome %d, %s", 1, "hi");
??? ShowMessage(szBuffer);
??? vsprintf(szBuffer, "welcome %d, %s", 1, "hi"); //<-提示[C++ Error] Unit1.cpp(24): E2034 Cannot convert 'int' to 'void *'
??? ShowMessage(szBuffer);

?

?

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉