我在C++程序中找到了一段代码,似乎它for()在这个程序中的每个循环中循环两次,但为什么在这样的预处理器定义中它需要第三个呢?
#define for for(int z=0;z<2;++z)for
我正在使用find()函数测试std :: list.在我将它实现到我的程序之前,我想看看它们是否会像我认为的那样工作.起初效果很好:`
list<int> l;
l.push_back(1);
l.push_back(2);
l.push_back(9);
list<int>::iterator it = find(l.begin(), l.end(), 9);
if (*it == 9)
{
cout << "Found";
}
else
{
cout << "Not Found";
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,输出是"Found",这是正确的,但是当我这样做时:
list<int> l;
l.push_back(1);
l.push_back(2);
l.push_back(9);
list<int>::iterator it = find(l.begin(), l.end(), 3);
if (*it == 9)
{
cout << "Found";
}
else
{
cout << "Not Found";
}
Run Code Online (Sandbox Code Playgroud)
它没有输出任何内容,但它应该输出"Not Found",我得到一个"Debug Assertion Failed!" 错误,它说"表达式:列表迭代器不能解除引用",我怎么能解决这个问题?