0

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:

// 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> >&)'

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by jencas
0

... 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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.