CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Threaded View

  1. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: push_back on a vector crashing

    For an example:
    Code:
    #include <algorithm>
    
    bool isPassingGrade(const Student_info& info)
    {
        return !fgrade(info);
    }
    
    vector<Student_info> extract_fails(vector<Student_info>& students)
    {
        // Partition students -- passing is on left of partition, failing is on right of partition
        vector<Student_info>::iterator it = std::stable_partition(students.begin(), students.end(), isPassingGrade);
    
        // iterator "it" is the partition point, so erase failures starting there
        students.erase(it, students.end());
        return students;
    }
    All of that code that you're writing is in those few lines.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 1st, 2012 at 04:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured