How to print the second row of a 2D vector in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

int main() {
    std::vector<std::vector<int>> matrix {
        { 1, 4, 8, 9 },
        { 8, 3, 5, 1 },
        { 7, 0, 6, 2 }
    };

    int cols = matrix[0].size();

    for (int j = 0; j < cols; j++) {
        std::cout << matrix[1][j] << " ";
    }
}

   
    
/*
run:

8 3 5 1     

*/

 



answered Mar 15, 2024 by avibootz

Related questions

2 answers 142 views
1 answer 110 views
2 answers 726 views
2 answers 163 views
163 views asked Nov 18, 2022 by avibootz
2 answers 179 views
1 answer 135 views
...