int main()
{
const int SIZE = 10;
int a[SIZE] = {10, 2, 35, 5, 10, 26, 67, 2, 5, 10};
std::ostream_iterator<int> output(cout, " ");
std::vector<int> v(a, a + SIZE);
std::vector<int>::iterator newLastElement;
cout << "contents of the vector: ";
std::copy(v.begin(), v.end(), output);
newLastElement = std::remove(v.begin(), v.end(), 10);
cout << "\ncontents of the vector after remove: ";
//std::copy(v.begin(), newLastElement, output);
//this gives the correct result : 2 35 5 26 67 2 5
std::copy(v.begin(), v.end(), output);
//this gives a 10 which was supposed to be removed : 2 35 5 26 67 2 5 2 5 10
cout << endl;
return 0;
}
सरणी में तीन 10 हैं।एसटीएल हटाने की उम्मीद के रूप में काम नहीं करता है?
हटाए गए फ़ंक्शन के साथ सभी 10s को हटाने के बाद सरणी v में 10 क्यों शामिल हैं।
आप संकलित उत्पादन देख सकते हैं भी here
वैसे, यह टिप्पणी है ('// यह सही परिणाम देता है: 2 35 5 26 67 2 5 2 5') प्रोग्राम वास्तव में क्या उत्सर्जित करता है? आप वास्तव में '2 35 5 26 67 2 5' कहना चाहते थे, है ना? –
हां, बिल्कुल सही। – munish