C++ vector - find elements inside a vector and create a new vector
Markus Freitag
3,791
Reputation points
Hello,
Unfortunately, there is still a problem.
https://learn.microsoft.com/en-us/answers/questions/1031079/c-vector-find-element.html
struct PanelData
{
// **
CString Price;
CString IdentNo;
bool PanelReported;
};
vector<PanelData> m_dequePanelData;
vector<PanelData> m_Result;
Is there a way that returns me a new vector list, here all values of the PanelReported variable is true.
std::vector<PanelData>::iterator it;
it = find(m_dequePanelData.begin(), m_dequePanelData.end(), []( const PanelData& d ) { return d.PanelReported; } );
//std::vector<PanelData>::iterator it2;
//auto it2 = find(m_dequePanelData.begin(), m_dequePanelData.end(), [](const PanelData& d) { return d.PanelReported; });
//In C# I have FirstOrDefault() or ToList() I am looking for similar.
//What is the correct name in C++, what functions are similar?
The simplest solution just go through the list, think a std function is faster, better.
for (auto it = m_DicProcessdata.begin(); it != m_DicProcessdata.end(); ++it)
{
Thanks!
Developer technologies | C++
3,973 questions
Sign in to answer