Dev C++ 未检测到有关仅将单个尖括号与 cout 一起使用的错误?

Dev C++ not detecting error about using only single angle bracket with cout?

我有一个用 C++ 实现邻接矩阵的程序。
这是我的代码-

#include<iostream>

using namespace std;

void addEdge(int * add){
    cout<<"Edge added successfully.\n";
    *add = 1;
}

int main(){
    
    int vertex;
    
    cout<<"Enter number of vertices in the graph: ";
    cin>>vertex;
    
    int adjMat[vertex][vertex];
    
    for(int i=0;i<vertex;i++){
        for(int j=0;j<vertex;j++){
            adjMat[i][j] = 0;
        }
    }
    
    cout<<"\n";
    cout<<"Add edges (from and to): ";
    int from,to;
    while(cin>>from>>to){
        if((from >= vertex || from < 1) || (to >= vertex || to < 1)){
            cout<"Warning: Out of bound index.\n";
        }else{
            addEdge(&adjMat[--from][--to]);
        }
    }
    
    cout<<"\n";
    for(int i=0;i<vertex;i++){
        for(int j=0;j<vertex;j++){
            cout<<adjMat[i][j]<<" ";
        }
        cout<<"\n";
    }
    
    return 0;
}

在我的程序中,我错误地编写了一个错误并编译了程序,但 dev C++ 编译器没有给出错误,程序 运行 很好。
这是那部分-

while(cin>>from>>to){
        if((from >= vertex || from < 1) || (to >= vertex || to < 1)){
            cout<"Warning: Out of bound index.\n";
        }else{
            addEdge(&adjMat[--from][--to]);
        }
    }

我从其他编译器收到正确的错误消息。

编译器正在利用 ostreamoperator bool。在 C++ 11 之前,它被实现为 operator void * 并返回 void* 而不是 bool 导致语法上合法(但逻辑上不正确)的指针 < 指针比较。您已经找到了将运算符替换为现代 bool 版本的众多充分理由之一。

评论者在“不要使用如此古老的编译器”问题下方的建议成立,但根据您安装的 Dev-C++ 的年龄,最简单的解决方案可能是 turn on C++11 support. If your copy of Dev-C++ is too old for that, and you still want to use it, I join drescherjm in recommending you replace the compiler it came with with an up-to-date compiler from msys2. .

如果您想继续使用 Dev C++ 但不关心版本,here's a link to the most up-to-date version that I'm aware of。它与 GCC 9.3 捆绑在一起,在撰写本文时它只有一年的历史并支持 C++17。