📜  C / C++中的wcsncat()函数

📅  最后修改于: 2021-05-30 13:38:24             🧑  作者: Mango

wcsncat()函数将字符附加到目标,包括终止的null宽字符。如果source中字符串的长度小于num 。然后,仅复制直到终止的null宽字符的内容。

句法:

wchar_t* wcsncat (wchar_t* destination, const wchar_t* source, size_t num)

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

  • destination:指定指向目标数组的指针
  • source:指定要添加到目标的字符串
  • num:指定要添加的最大字符数

返回值:该函数返回目的地

下面的程序说明了上述函数:

程序1:

// C++ program to illustrate
// wcsncat() function
#include 
using namespace std;
  
int main()
{
    // maximum length of the destination string
    wchar_t destination[20];
  
    // maximum length of the source string
    wchar_t source[20];
  
    // initialize the destination string
    wcscpy(destination, L"Geekforgeeks ");
  
    // initialize the source string
    wcscpy(source, L"is the best");
  
    // initialize the length of
    // the resulted string you want
    wcsncat(destination, source, 20);
    wprintf(L"%ls\n", destination);
    return 0;
}
输出:
Geekforgeeks is the best

程序2:

// C++ program to illustrate
// wcsncat() function
#include 
using namespace std;
  
int main()
{
    // maximum length of the destination string
    wchar_t destination[40];
  
    // maximum length of the source string
    wchar_t source[40];
  
    // initialize the destination string
    wcscpy(destination, L"only some of the  ");
  
    // initialize the source string
    wcscpy(source, L"letters will be copied");
  
    // initialize the length of
    // the resulted string you want
    wcsncat(destination, source, 20);
    wprintf(L"%ls\n", destination);
    return 0;
}
输出:
only some of the  letters will be copi
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”