如何检查3d数组的元素是否为空?

时间:2020-04-20 10:11:02

标签: c++ arrays pointers multidimensional-array

我有一个填充的3d数组和一个打印每个2d数组的所选行的函数,但是如果所选行(从第一个数组开始)为空,则应打印“行为空”,我不知道如何检查它是否为空。 我尝试了以下方法:

void printrow(int X[][4][5], int row){
    if(X[0][row][0]==0){
        cout <<"row empty";
    }
    else{
        for(int i=0; i < 4; i++){
            for(int j=0; j < 5;j++){
                cout << X[i][row][j] << " ";
             }
        }
        cout << endl;  
    }
}

也许我应该使用一个指针?如果是,该怎么办?

1 个答案:

答案 0 :(得分:1)

您可以使用std::optional

  db.collection('users').doc{{userid}) // Each doc stores data under 'userinfo' index, which is an object(map).
  db.collection('posts').doc({postid}) // Each doc contains 'userinfo', which is the data about the person who posted.
  db.collection('saved').doc({userid}) // Each doc stores data under 'saved' index, which is an array of carbon copy of a document in 'posts' collection.
相关问题