名稱空間
變體
操作

std::strncat

來自 cppreference.com
< cpp‎ | string‎ | byte
在標頭檔案 <cstring> 中定義
char* strncat( char* dest, const char* src, std::size_t count );

src 所指向的位元組字串附加到 dest 所指向的位元組字串末尾。最多複製 count 個字元。結果位元組字串以空字元結尾。

目標位元組字串必須有足夠的空間容納 destsrc 的內容,再加上終止的空字元,但 src 的大小受限於 count

如果字串重疊,則行為未定義。

目錄

[edit] 引數

dest - 指向要追加的以空字元結尾的位元組字串的指標
src - 指向要複製的以空字元結尾的位元組字串的指標
count - 要複製的最大字元數

[edit] 返回值

dest

[edit] 注意

因為 std::strncat 每次呼叫都需要尋找到 dest 的末尾,所以使用 std::strncat 將多個字串連線成一個字串效率很低。

[edit] 示例

#include <cstdio>
#include <cstring>
 
int main() 
{
    char str[50] = "Hello ";
    const char str2[50] = "World!";
    std::strcat(str, str2);
    std::strncat(str, " Goodbye World!", 3); // may issue "truncated output" warning
    std::puts(str);
}

輸出

Hello World! Go

[edit] 參閱

連線兩個字串
(函式) [編輯]
將一個字串複製到另一個字串
(函式) [編輯]
C 文件 中的 strncat