C++ STL 列表迭代器

标签 c++ list stl compiler-errors iterator

我正在尝试使用以下代码遍历字符串列表:

#include<cstdlib>
#include<string>
#include<list>

using namespace std;

list<string> dict = {"aardvark", "ambulance", "canticle", "consumerism"};
list<string> bWords = {"bathos", "balderdash"};
//splice the bWords list into the appropriate spot in dict
auto iterLastB = --(bWords.end());
//find spot in dict
list<string>::iterator it = dict.begin();
while(it != dict.end()){
  if(*it > *iterLastB)
    break;
    ++it;
}
dict.splice(it, bWords);

但是,在构建它时,我收到错误 expected unqualified-id before 'while' 这是什么意思,我该如何解决这个问题?

最佳答案

你不能那样直接写代码。至少您需要一个 main 函数。您可能应该在 main 函数中添加所有内容(包括的内容除外)。

关于C++ STL 列表迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11679459/

相关文章:

c++ - C++:从std::list删除指针

python - 列表子集的函数列表

c++ - 在std::qsort的compare函数中处理错误情况

c++ - 关于c++中 vector 的地址

c++ - 为什么我不能删除 vector 的最后一个元素

c++ - POD 类型的原子位操作

c++ - 一种无需 XAML 即可关闭 DirectX Metro 应用程序的方法

c# - 将非托管 unicode 字符串编码到 .net。高字符替换为问号

list - 柏树 headless (headless)测试中未呈现 w2ui 覆盖

python - 如何从 pandas 数据帧创建字典的字典?