简体   繁体   中英

What is the efficient way to take 2d vector input in c++?

3    //number of lines
1 2  
2 1
4 5

I want to store the n lines as a 2d vector, what is the best way to do it?

int t;
cin>>t;
std::vector<std::vector<int>> Vec(t, std::vector<int>(2, 0)); // replace zero with some value if you wanna intiallize vector.
for(int i=0; i<t; i++){
    for(int j=0; j<2; j++{
        cin>>Vec[i][j];
    }
}

this is the way i always intiallize a 2d vector and take input. I feel there is nothing more efficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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