std::wcsncpy - cppreference.com
提供: cppreference.com
<tbody> </tbody>
|
|
||
src の指すワイド文字列の最大 count 文字 (終端のヌルワイド文字を含む) を dest の指すワイド文字配列にコピーします。
文字列 src 全体がコピーされる前に count に達した場合、結果のワイド文字配列はヌル終端されません。
src から終端のヌルワイド文字をコピーした後、 count に達していなけえれば、合計 count 文字が書き込まれるまで、追加のヌルワイド文字が dest に書き込まれます。
文字列がオーバーラップしている場合、動作は未定義です。
引数
| dest | - | コピー先のワイド文字配列を指すポインタ |
| src | - | コピー元のワイド文字列を指すポインタ |
| count | - | コピーする最大ワイド文字数 |
戻り値
dest。
ノート
一般的な使い方では、 count はコピー先配列のサイズです。
例
#include <iostream> #include <cwchar> int main() { wchar_t src[] = L"hi"; wchar_t dest[6] = {L'a', L'b', L'c', L'd', L'e', L'f'}; std::wcsncpy(dest, src, 5); // this will copy hi and repeat \0 three times std::wcout << "The contents of dest are: "; for(wchar_t c : dest) { if(c) std::wcout << c << ' '; else std::wcout << "\\0" << ' '; } std::wcout << '\n'; }
出力:
The contents of dest are: h i \0 \0 \0 f