Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 关于c+上列表的问题+;_C++_List - Fatal编程技术网

C++ 关于c+上列表的问题+;

C++ 关于c+上列表的问题+;,c++,list,C++,List,考虑按给定顺序包含以下字符串的字符串列表: "bob" "ann" "sue" "ned": [0] [1] [2] [3] respectively 在每次操作后给出列表的内容 a. list.insert(2, "bob"); b. list.insert(5, "ann"); c. list.remove(0); d. list.remove(3); I got...bob, ann, bob, sue, ned; bob, ann, bob, sue, ned, a

考虑按给定顺序包含以下字符串的字符串列表:

"bob" "ann" "sue" "ned":   [0]   [1]   [2]   [3] respectively
在每次操作后给出列表的内容

a. list.insert(2, "bob");
b. list.insert(5, "ann");
c. list.remove(0);
d. list.remove(3);

I got...bob, ann, bob, sue, ned;
 bob, ann, bob, sue, ned, ann;
ann, bob, sue, ned, ann;
ann, bob, sue, ann

这是正确的吗?

遵循此操作,您将了解如何插入值。使用
迭代器
插入值。该值将在当前迭代器位置之前插入。因为
iterator.end()
将是最后一个位置,所以您不能超过这个位置。使用
push_back()
将元件插入末端

为什么你怀疑这些结果可能不正确?很简单:试试看。下一点:比“列表”更精确一点会很有帮助。快速看一下文档也会回答这个问题。我怀疑结果可能不正确,主要是因为b。我知道现在列表上有4个项目,但我不知道如果第5个索引不存在,我们是否可以引用它。欢迎访问。请检查.AFAIK插入函数的第一个参数是迭代器。你怎么能给出一个整数值呢??同样,remove函数接受要删除的值作为参数,而不是索引。