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 6538285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:43:06+00:00 2026-05-25T10:43:06+00:00

double * values; // instead of this, std::vector<double> values; // I want this. An

  • 0
double * values; // instead of this,
std::vector<double> values; // I want this.

An API I’m using provides a result as double* pointer. I want to wrap this with the std::vector<double> type.

  • 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-05-25T10:43:07+00:00Added an answer on May 25, 2026 at 10:43 am

    You can’t wrap an array in a vector in place and expect the vector to operate on that array. The best you can do is give the vector the double* and the number of values, which will have the vector make a copy of every element and put it in itself:

    int arrlen = 0;
    
    // pretending my_api takes arrlen by reference and sets it to the length of the array
    double* dbl_ptr = my_api(arrlen); 
    
    vector<double> values(dbl_ptr, dbl_ptr + arrlen);
    
    // note that values is *not* using the same memory as dbl_ptr
    // so although values[0] == dbl_ptr[0], &values[0] != &dbl_ptr[0]
    

    And also, like Praetorian said, if the API you are using expects you to free the memory after using it, you might be interested in smart pointers. See Praetorian’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some double values I want to convert to a string with this
I am trying to get double values from file using fscanf function. I am
I want to save values as an ArrayList of double in a file. Whenever
I have problem in getting wrong values in array of double. Instead of getting
I have a class containing a number of double values. This is stored in
#include <iostream> #include <string> using namespace std; int main() { double age; double months;
I have double values which I would like to convert to String values with
I have a set of three double values as part of an anonymous expression
I have table which contains double values stored in mysql database ...I need to
I have a string that contains a known number of double values. What's the

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.