I have a segmentation fault in c++, where did I go wrong?

Trying to traverse a 2d vector in order to find index(es) of a certain key value which is the number 1. I looked up what a segmentation fault was and it said that it happens when you try to access too much memory, but I don't get how I'm doing that.

#include<iostream>
#include<algorithm>
#include <vector>
#include <cmath>

using namespace std;
int main(){
    vector<vector<int>> matrix;
    int n;
    int i = 0;
    int j = 0;
    for (int i =0; i<5; i++){
        for (int z = 0; z<5; z++){
            cin >> n;
            matrix[i][z] = n;
        }

    }
    while (matrix[i][j] != 1 && ((i && j) < matrix.size())){
        while (i != 5){
            i++;
            while (j != 5){
                j++;
            }
        }

    }
    cout << abs((2-j) + (2-i)) << endl;


}


from Recent Questions - Stack Overflow https://ift.tt/33nRHWn
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation