首頁 >後端開發 >C++ >在C/C++中,wcspbrk()函數的翻譯如下:

在C/C++中,wcspbrk()函數的翻譯如下:

WBOY
WBOY轉載
2023-08-27 12:41:06967瀏覽

在C/C++中,wcspbrk()函數的翻譯如下:

wcspbrk()函數是C或C 的內建函數。它在一個寬字串中搜尋另一個寬字串中存在的一組寬字元。此函數位於cwhar頭檔中。

此函數接受兩個參數。第一個參數是目標字串,第二個參數是來源字串。作為目標字串,我們必須傳遞以空字元結尾的寬字串進行搜尋。作為來源字串,我們必須傳遞以空字元結尾的寬字串,其中包含要搜尋的字元。

此函數傳回兩個值。如果目標字串或來源字串中存在一個或多個寬字符,則函數將傳回指向目標字串和來源字串中第一個寬字符的指標。如果目標字串或來源字串中沒有寬字符,則傳回一個空指標。

範例

<span class="com">#include</span><span class="pln"> </span><span class="str"><cwchar></span>
<span class="com">#include</span><span class="pln"> </span><span class="str"><iostream></span>
<span class="kwd">using</span><span class="pln"> </span><span class="kwd">namespace</span><span class="pln"> std</span><span class="pun">;</span>
<span class="pln">main </span><span class="pun">() {</span>
<span class="typ">   wchar_t</span><span class="pln"> wcs</span><span class="pun">[]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> L</span><span class="str">"Hello World. This is C++ PROGRAM."</span><span class="pun">;</span>
<span class="typ">   wchar_t</span><span class="pln"> key</span><span class="pun">[]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> L</span><span class="str">"aeiouAEIOU"</span><span class="pun">;</span>
<span class="typ">   wchar_t</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> pwc</span><span class="pun">;</span>
<span class="pln">   wcout </span><span class="pun"><<</span><span class="pln"> L</span><span class="str">"Vowels in &#39;"</span><span class="pun"><<</span><span class="pln"> wcs </span><span class="pun"><<</span><span class="pln"> </span><span class="str">"&#39;: "</span><span class="pun">;</span>
<span class="pln">   pwc </span><span class="pun">=</span><span class="pln"> wcspbrk </span><span class="pun">(</span><span class="pln">wcs</span><span class="pun">,</span><span class="pln"> key</span><span class="pun">);</span>
<span class="kwd">   while</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pwc </span><span class="pun">!=</span><span class="pln"> NULL</span><span class="pun">) {</span>
<span class="pln">      wcout </span><span class="pun"><<</span><span class="pln"> </span><span class="pun">*</span><span class="pln">pwc </span><span class="pun"><<</span><span class="pln"> L</span><span class="str">" "</span><span class="pun">;</span>
<span class="pln">      pwc </span><span class="pun">=</span><span class="pln"> wcspbrk </span><span class="pun">(</span><span class="pln">pwc</span><span class="pun">+</span><span class="lit">1</span><span class="pun">,</span><span class="pln">key</span><span class="pun">);</span>
<span class="pun">   }</span>
<span class="pln">   wcout </span><span class="pun"><<</span><span class="pln"> L</span><span class="str">"\n"</span><span class="pun">;</span>
<span class="pun">}</span>

輸出

Vowels in &#39;Hello World. This is C++ PROGRAM.&#39;: e o o i i O A

以上是在C/C++中,wcspbrk()函數的翻譯如下:的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除