小编are*_*pau的帖子

第三个'for'在#define for for(int z = 0; z <2; ++ z)中的含义是什么?

我在C++程序中找到了一段代码,似乎它for()在这个程序中的每个循环中循环两次,但为什么在这样的预处理器定义中它需要第三个呢?

#define for for(int z=0;z<2;++z)for

c++ c-preprocessor

5
推荐指数
1
解决办法
401
查看次数

std :: list和find(),如果找不到使用list in list错误的item/value错误

我正在使用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!" 错误,它说"表达式:列表迭代器不能解除引用",我怎么能解决这个问题?

c++ algorithm list find

0
推荐指数
1
解决办法
604
查看次数

标签 统计

c++ ×2

algorithm ×1

c-preprocessor ×1

find ×1

list ×1