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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:04:59+00:00 2026-06-10T04:04:59+00:00

I have a 1D vector(Vp_cpp) and I want to convert to 2D vector(declared as

  • 0

I have a 1D vector(Vp_cpp) and I want to convert to 2D vector(declared as Vp_2D). However, my implementation is somewhat not correct because it couldn’t be able to reach the line “Out from inner loop”.

std::vector<double> Vp_cpp;
std::vector<std::vector<double> > Vp_2D;

Vp_2D.resize(N_cpp);
for (int i = 0; i < N_cpp; ++i)
    Vp_2D[i].resize(N_cpp);
for (int j = 0; j < N_cpp; j++)
    for (int k = 0; k < N_cpp; k++)
{
    cout << "Beginning inner loop" << endl;
    Vp_2D[i_cpp][i_cpp2] = Vp_cpp[i_cpp2]; 
    cout << "Out from inner loop" << endl;
}

What could be wrong?

  • 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-10T04:05:01+00:00Added an answer on June 10, 2026 at 4:05 am

    This line seems wrong to me:

    Vp_2D[i_cpp][i_cpp2] = Vp_cpp[i_cpp2]; 
    

    I would write:

    Vp_2D[j][k] = Vp_cpp[i++];
    

    where i is used to iterate over Vp_cpp. It should be initialized to 0 before the for (int j, ... loop.

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

Sidebar

Related Questions

I have a vector of integers and I want to convert it to a
I have vector< pair<int, int>> myVec (N); I want to have all pairs initialized
I have the vector d<-1:100 I want to sample k=3 times from this vector
Let's say I have: vector<T *> vect; I know it's not the obvious way
I have vector of strings and want to create a fixed with string out
I have a vector< vector<string> > and want to add a string to the
I have some vector of elements passed to a function and I want to
I have vector with 6 numbers, which I want insert to list and add
I have vector data for buildings on my map and want them to appear
I have Vector declared in index.jsp page like this: <%! Vector vNumbers = new

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.