• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <string>

    std::char_traits::copy

    static char_type* copy(char_type* s1,
                           const char_type* s2,
                           std::size_t n);                // (1) C++03
    
    static constexpr char_type* copy(char_type* s1,
                                     const char_type* s2,
                                     std::size_t n);      // (1) C++20
    

    概要

    文字列s1に文字列s2をコピーする。

    事前条件

    範囲[s1, s1+n)と範囲[s2, s2+n)が重なっていないこと。

    効果

    範囲[0, n)の各iについて、assign(s1[i], s2[i])を実行する。

    戻り値

    コピー完了後のs1を返す。

    計算量

    線形時間

    #include <iostream>
    #include <string>
    
    int main()
    {
      const std::size_t n = 5 + 1;
      char s[n] = "abcde";
    
      char result[n];
      std::char_traits<char>::copy(result, s, n);
    
      std::cout << result << std::endl;
    }
    

    出力例

    abcde
    

    参照