C/C中的vswscanf()函数++

这个 vfwscanf() C++中的函数用于从宽字符串读取格式化数据到变量参数列表。它还从宽字符串缓冲区读取宽字符串。此函数用于从中读取数据 ws 并根据 总体安排 进入变量参数列表中元素所指向的位置 阿格 . 定义见 图书馆档案。

null

语法:

int vswscanf( const wchar_t* ws, const wchar_t* format, va_list arg )

参数: 该函数接受三个强制性参数,如下所述:

  • ws: 指向以null结尾的宽字符串的指针,用于读取数据
  • 格式: 指向以null结尾的宽字符串的指针,该字符串指定如何读取输入
  • arg: 一个值,用于标识用va_start初始化的变量参数列表。

返回值: 该函数返回两个值,如下所示:

  • 成功时,它返回成功读取的参数数。
  • 一旦失败, EOF 归还

以下程序说明了上述功能: 项目1:

// C++ program to illustrate the
// vswscanf() function
#include <bits/stdc++.h>
using namespace std;
// ws : pointer to the wide string
// format : to read the input
void wideMatch( const wchar_t * ws, const wchar_t * format, ...)
{
va_list arg;
// A function that invokes va_start
// shall also invoke va_end before it returns.
va_start (arg, format);
// vswscanf() reads formatted data from wide
// string into variable argument list
vswscanf(ws, format, arg);
va_end (arg);
}
// Driver code
int main()
{
setlocale (LC_ALL, "en_US.UTF-8" );
// initialize the buffer
wchar_t wideS[] = L "GFG" ;
wchar_t string[20];
wideMatch(wideS, L "%ls" , string);
wprintf(L "Random Symbols are :" );
// print all the symbols
for ( int i = 0; i < wcslen(string); i++) {
putwchar(string[i]);
putwchar( ' ' );
}
return 0;
}


输出:

Random Symbols are :
G F G

项目2:

// C++ program to illustrate the
// vswscanf() function
#include <bits/stdc++.h>
using namespace std;
void WideString( const wchar_t * ws, const wchar_t * format, ...)
{
va_list arg;
// A function that invokes va_start
// shall also invoke va_end before it returns.
va_start (arg, format);
// vswscanf() reads formatted data from wide
// string into variable argument list
vswscanf(ws, format, arg);
va_end (arg);
}
// Driver code
int main()
{
int value;
// initialize the buffer
wchar_t wideS[] = L "100 websites of GeekforGeeks" ;
WideString(wideS, L " %d %ls " , &value, wideS);
// print all the symbols
wprintf(L "Best: %lsQuantity: %d" , wideS, value);
return 0;
}


输出:

Best: websites
Quantity: 100

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享