How can I copy a part of an array to another array in C++?

前端 未结 5 1618
执笔经年
执笔经年 2021-02-05 10:07

This is the same question asked in C# but i need for C++

How can I copy a part of an array to another array?

Consider I\'m having

    int[] a = {         


        
5条回答
  •  礼貌的吻别
    2021-02-05 10:51

    Yes, use std::copy:

    std::copy(a + src_begin_index,
              a + src_begin_index + elements_to_copy,
              b + dest_begin_index);
    

    The equivalent of your C# example would be:

    std::copy(a + 1, a + 4, b);
    

提交回复
热议问题