简体   繁体   English

c++ 检查数组是否等于数组未生成

[英]c++ check if array equals array not made

Ddoes any body know how do do this? Ddoes 任何机构知道如何做到这一点? Thanks if you do.谢谢,如果你这样做。 I am new in c++. I don't know what do do.我是c++的新人。我不知道该做什么。 Python is much better in my opinion. Python 在我看来要好得多。

#include <bits/stdc++.h>
using namespace std;
int main(){
    int nums[] = {1, 2, 3, 4};
    if (nums == [1, 2, 3, 4]){
        cout<<1;
    }
}

You should use std::array instead of plain arrays to realize this.您应该使用std::array而不是普通的 arrays 来实现这一点。

#include <iostream>
#include <array>

int main(void) {
    std::array<int, 4> nums = {1, 2, 3, 4};
    if (nums == std::array<int, 4>{1, 2, 3, 4}){
        std::cout<<1;
    }
}

Also see:另见:

From C++17, you can use class template argument deduction to simplify MikeCAT's solution like this:从 C++17 开始,您可以使用 class 模板参数推导来简化 MikeCAT 的解决方案,如下所示:

std::array nums = {1, 2, 3, 4};
if (nums == std::array{1, 2, 3, 4}) {
    std::cout << 1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM