//list容器
#include
#include
using namespace std;
int main(void)
{
string str[] = { "hello","world","!" }, str1;
std::list
for (size_t i = 0; i != 3; i++)
strs.push_back(str[i]);
cout << "请输入需要删除的值" << endl<< "hello, world, !"<
for (std::list
{
if (str1 == *it)
strs.erase(it++);
else
it++;
}
cout << "剩下的值" << endl;
for (std::list
cout << *it;
return 0;
}
//deque容器
#include
#include
using namespace std;
int main(void)
{
string str[] = { "hello","world","!" }, str1;
std::deque
for (size_t i = 0; i != 3; i++)
strs.push_back(str[i]);
cout << "请输入需要删除的值" << endl << "hello, world, !" << endl;
cin >> str1;
for (std::deque
{
if (str1 == *it)
{
it=strs.erase(it);//返回下个it坐标即it++赋值给it;
}
}
cout << "剩下的值" << endl;
for (std::deque
cout << *it;
return 0;
}
编写程序处理一个string类型的list容器。在该容器9.27:中寻找一个特殊值,如果找到,则将它删除掉。用deque容器重写上述程序。
时间:2023-05-30
相关推荐