I have std :: vector m_vPaths; I will iterate over this vector and call :: DeleteFile (strPath) when I go. If I successfully delete the file, I will delete it from the vector. My question is: can I get around to using two vectors? Is there any other data structure that might be better suited for what I need to do?
Example: using iterators almost does what I want, but the problem is that you delete with an iterator, all iterators become invalid.
std::vector<std::string> iter = m_vPaths.begin(); for( ; iter != m_vPaths.end(); iter++) { std::string strPath = *iter; if(::DeleteFile(strPath.c_str())) { m_vPaths.erase(iter);
I can use two vectors and I will no longer have a problem, but is there a better, more efficient way to do what I'm trying to do?
btw, if it is unclear, m_vPaths is declared like this (in my class):
std::vector<std::string> m_vPaths;
c ++ iterator loops data-structures vector
cchampion Oct 22 '09 at 1:37 2009-10-22 01:37
source share