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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:36:33+00:00 2026-06-08T09:36:33+00:00

I am having another problem with manipulating data in a C++ array. I now

  • 0

I am having another problem with manipulating data in a C++ array. I now want to decimate the array by removing all the zeros from it.

So for example say before I had array[4] = {1,2,0,0,4} It would become array[3] = {1,2,4}.

I know that I will need to use a for loop to iterate through the array storing the main data and that I will most likely need to initialize a new array to store the decimated data but I am not quite sure how to go about it.

  • 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-08T09:36:35+00:00Added an answer on June 8, 2026 at 9:36 am

    If you have to resize array’s why not simply use std::vector. The example does it.

    #include <vector>
    #include <algorithm>
    
    bool isZero (int i) 
    {
        return i == 0;
    }
    
    int main()
    {
    
        std::vector<int> myarray;
    
        myarray.push_back( 0 );
        myarray.push_back( 1 );
        myarray.push_back( 0 );
        myarray.push_back( 3 );
        myarray.push_back( 9 );
    
        std::vector<int>::iterator newIter = std::remove_if( myarray.begin() , myarray.end() , isZero);
        myarray.resize( newIter -  myarray.begin() );
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Android Launch an application from another application I am having a problem
After getting the right answer from this question , I am having another problem
Okay, I am having another UITableView problem. For some reason the indexPath.row is all
having another problem with my javascript for my table. Basically, if you look at
I saw the other topic and I'm having another problem. The process is starting
I am having a problem when setting VB.NET list object to another. In the
I'm having a problem with running an application I made on another computer. This
I'm having a problem with logic programming, but I think that could be another
CakePHP Newbie :) I am having trouble accessing another controller and passing that data
I'm having another problem with this exercise: http://lpmj.net/20.php My problem is that when i

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.