Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::strncat

      From cppreference.com
      <cpp‎ |string‎ |byte
       
       
       
       
      Defined in header<cstring>
      char* strncat(char* dest,constchar* src,std::size_t count);

      Appends a byte string pointed to bysrc to a byte string pointed to bydest. At mostcount characters are copied. The resulting byte string is null-terminated.

      The destination byte string must have enough space for the contents of bothdest andsrc plus the terminating null character, except that the size ofsrc is limited tocount.

      The behavior is undefined if the strings overlap.

      Contents

      [edit]Parameters

      dest - pointer to the null-terminated byte string to append to
      src - pointer to the null-terminated byte string to copy from
      count - maximum number of characters to copy

      [edit]Return value

      dest

      [edit]Notes

      Becausestd::strncat needs to seek to the end ofdest on each call, it is inefficient to concatenate many strings into one usingstd::strncat.

      [edit]Example

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

      Output:

      Hello World! Go

      [edit]See also

      concatenates two strings
      (function)[edit]
      copies one string to another
      (function)[edit]
      C documentation forstrncat
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/byte/strncat&oldid=152886"

      [8]ページ先頭

      ©2009-2025 Movatter.jp