std::copy two dimensional array

前端 未结 1 694
灰色年华
灰色年华 2021-02-06 01:34

Hello I\'m trying to use the std::copy() function to copy a two dimensional array. I was wondering if it\'s possible to do it like so! I keep getting a \"Segmentation Fault\"

1条回答
  •  走了就别回头了
    2021-02-06 01:39

    std::copy(myint, myint+rows*columns,favint);
    

    should be:

    std::copy(&myint[0][0], &myint[0][0]+rows*columns,&favint[0][0]);
    

    prototype of std::copy:

    template< class InputIt, class OutputIt >
    OutputIt copy( InputIt first, InputIt last, OutputIt d_first );
    

    Notice that pointer to array element could be wrapper as an iterator.

    0 讨论(0)
提交回复
热议问题