我正在尝试使用以下代码遍历字符串列表:
#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/