std::strncpy
提供: cppreference.com
|
|
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
| Defined in header <cstring>
|
||
| char *strncpy( char *dest, const char *src, std::size_t count ); |
||
バイト文字列の中で最も
count文字でコピーがsrcが指す文字配列にdest(終端のNULL文字を含む)に指さ. Original:
Copies at most
count characters of the byte string pointed to by src (including the terminating null character) to character array pointed to by dest. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
文字列全体の
countがコピーされた前srcに達した場合は、結果の文字列はNULL終端ではない.Original:
If
count is reached before the entire string src was copied, the resulting character array is not null-terminated.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
src達していないcount文字の合計が書き込まれるまでdestから終端のNULL文字をコピーした後、追加のNULL文字がcountに書き込まれ、IF.Original:
If, after copying the terminating null character from
src, count is not reached, additional null characters are written to dest until the total of count characters have been written.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
文字列が重複している場合は、動作は未定義です.
Original:
If the strings overlap, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集] パラメータ
| dest | - | コピー先の文字配列へのポインタ
Original: pointer to the character array to copy to The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| src | - | からコピーするバイト文字列へのポインタ
Original: pointer to the byte string to copy from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| count | - | コピーする最大文字数
Original: maximum number of characters to copy The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[編集] 値を返します
dest
[編集] 例
このコードを実行します
#include <iostream> #include <cstring> int main() { const char* src = "hi"; char dest[6] = {'a', 'b', 'c', 'd', 'e', 'f'};; std::strncpy(dest, src, 5); std::cout << "The contents of dest are: "; for (char c : dest) { if (c) { std::cout << c << ' '; } else { std::cout << "\\0" << ' '; } } std::cout << '\n'; }
出力:
The contents of dest are: h i \0 \0 \0 f
[編集] 参照
| 別の文字列をコピーします Original: copies one string to another The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数) | |
| 別のバッファにコピーします Original: copies one buffer to another The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数) | |
| C documentation for strncpy
| |