Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8887535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:49:58+00:00 2026-06-14T21:49:58+00:00

I used array to store the data, but I replaced with vector, so I

  • 0

I used array to store the data, but I replaced with vector, so I would like to replace all the c operators with c++ operators. I used memcpy to copy one memory blocks

for (i = 0; i < rows_; i++)
    memcpy((T *) &tmp.data_[cols_ * i], (T *) &a.data_[cols_ * (2 * i + 1)], rows_ * sizeof(T));

It’s also working with vectors, I just want to know is there an equivalent function in c++?

I tried the copy:

std::copy(tmp.data_[cols_ * i], tmp.data_[cols_ * i+rows], a.data_[cols_ * (2 * i + 1)]);

but I’m receiving the following error:

error: invalid use of member function (did you forget the ‘()’ ?)

For example:

I have an 2xnxn size array and I’m using the for cycle to make an nxn array instead. for example I have 1 2 3 4 5 6 7 8, my new array has to be the following: 3 4 7 8. I used memcpy to achieve this, but I don’t know how can I achieve in c++

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:49:59+00:00Added an answer on June 14, 2026 at 9:49 pm

    Use std::copy or std::vector::assign if you copy from array to vector

      int from_array[10] = {1,2,3,4,5,6,7,8,9,10};
    
      std::vector<int> to_vector;
    
      int array_len = sizeof(from_array)/sizeof(int);
      to_vector.reserve(array_len);
      std::copy( from_array, from_array+10, std::back_inserter(to_vector)); 
      or C++11
      std::copy( std::begin(from_array), std::end(from_array), std::back_inserter(to_vector));   
    
      std::vector<int> to_vector2;
      to_vector2.reserve(array_len);
      to_vector2.assign(from_array, from_array + array_len);
    

    if copy from vector to vector

       std::vector<int> v1;
       std::vector<int> v2;
       v2 = v1; // assign operator = should work
    

    if you don’t need to keep v1, std::swap also works

    v2.swap(v1);
    

    Update:

      const int M = 2;
      const int N = 4;
      int from_array[M][N] = {{1,2,3,4},{5,6,7,8}};
    
      std::vector<int> to_vector;
      to_vector.reserve(N);
      int start=2;
      int end = 4;
      for (int i=0; i<M; i++)
      {
        std::copy( from_array[i]+start, from_array[i]+end, std::back_inserter(to_vector)); 
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

which one should be used to manipulating data, Array or Array Object? Like search,sort
I am trying to store facebook user's data array in mysql. I have used
I have this 4 Dimensional array to store String values which are used to
In Ruby I can call methods with array elements used as positional parameters like
I used in my C++/CLI project static array's like: static array < array< String^>^>^
I'm dealing with very big data in matlab and used to store this data
I have a store like this: var store = new Ext.data.Store({ id: 'store', url:
I need to store a multi-dimensional associative array of data in a flat file
I am using the excellent Parse as a data store, but need to access
I am using a vector of strings in order to store some data in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.