| | |
Error: Erasing element from a Vector
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 150
Reputation:
Solved Threads: 7
Hello
I have a function that writes some text to a text file.
My Problem is: At one point I try to erase an element from a vector ,but I get an error & I dont know why, it looks sytaxically (is that a word?
) correct & I am including the correct libraries (vector, string etc)
function:
error:
I have a function that writes some text to a text file.
My Problem is: At one point I try to erase an element from a vector ,but I get an error & I dont know why, it looks sytaxically (is that a word?
) correct & I am including the correct libraries (vector, string etc)function:
C++ Syntax (Toggle Plain Text)
// pic_links is a private vector of the class generate_post void generate_post::delete_used_pics(char* file) { int match=0; ofstream outfile; outfile.open(file); if (!outfile) { cout << "Failed to open file"; } for (int i=0; i<(int)pic_links.size(); i++) { for (int j=0; j<6; j++) { if (pic_links.at(i) == post[j]) { match++; pic_links.erase(pic_links.at(i)); // the error occurs here } } if (match==0) { outfile << "http://inspic.com" << pic_links.at(i) << "\n"; } match=0; } outfile.close(); }
error:
•
•
•
•
no matching function for call to `std::vector<std::string, std::allocator<std::string> >::erase(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >&)'
Last edited by gretty; Aug 26th, 2009 at 6:35 am.
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
... and perform the outer loop in reverse direction to avoid problems with overlooking the next element after erasing or index going out of bounds when erasing the last element
If you are forced to reinvent the wheel at least try to invent a better one!
Please use code tags - Please mark solved threads as solved
Please use code tags - Please mark solved threads as solved
![]() |
Similar Threads
- Erasing element from a vector (C++)
- Adding element to a vector crashes it? (C++)
- Searching for and deleting an element in vector (C++)
- Pointer, vector, and/or deque problem (C++)
- error in Mac/IE 5.2 - this.element.style is not an object (HTML and CSS)
- Error pushing pointers to a vector (C++)
Other Threads in the C++ Forum
- Previous Thread: Moving columns...
- Next Thread: Can I use MIDI to play a specific frequency
Views: 417 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






