I have a program that reads a list of assignments and removes the "bad" assignments, then writes into a new file. My function that removes the bad assignments works correctly as well as the function that reads the text file. How can I utilize the std::list and std::algorithm library to write to an output file without using any direct loops? Below is the code I have implemented so far for the removing of the bad assignmemnts (Prune) along with reading the text file. Also below is what I am attempting to get working for the write function commented out
void Prune()
{
m_Assignments.remove_if([](const Assignment& assignment){ return !assignment.IsGood();});
}
void Read(std::istream& is)
{
std::string s;
std::getline(is, s);
//m_Name = s;
std::istream_iterator<Assignment> start(is);
std::istream_iterator<Assignment> stop;
std::copy(start,stop,std::back_inserter(m_Assignments));
}
void Write(std::ostream& os)
{
//std::list<Assignment>::iterator i = m_Assignments.begin();
//std::list<Assignment>::iterator j = m_Assignments.end();
//std::ostream_iterator<Assignment> (m_Assignments);
//std::ostream_iterator<Assignment>
//(std::copy(i,j,std::back_inserter(m_Assignments)));;
//std::ostream_iterator<Assignment> stop;
//std::copy(start,start,std::back_inserter(m_Assignments));
};
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire