//list容器
#include<iostream>
#include<list>
using namespace std;
int main(void)
{
string str[] = { "hello","world","!" }, str1;
std::list<string> strs;
for (size_t i = 0; i != 3; i++)
strs.push_back(str[i]);
cout << "请输入需要删除的值" << endl<< "hello, world, !"<<endl;
cin >> str1;
for (std::list<string>::iterator it = strs.begin(); it != strs.end();)
{
if (str1 == *it)
strs.erase(it++);
else
it++;
}
cout << "剩下的值" << endl;
for (std::list<string>::iterator it = strs.begin(); it != strs.end(); it++)
cout << *it;
return 0;
}
//deque容器
#include<deque>
#include<iostream>
using namespace std;
int main(void)
{
string str[] = { "hello","world","!" }, str1;
std::deque<string> strs;
for (size_t i = 0; i != 3; i++)
strs.push_back(str[i]);
cout << "请输入需要删除的值" << endl << "hello, world, !" << endl;
cin >> str1;
for (std::deque<string>::iterator it = strs.begin(); it != strs.end(); it++)
{
if (str1 == *it)
{
it=strs.erase(it);//返回下个it坐标即it++赋值给it;
}
}
cout << "剩下的值" << endl;
for (std::deque<string>::iterator it = strs.begin(); it != strs.end(); it++)
cout << *it;
return 0;
}