繁体   English   中英

在 c++ 中采用二维矢量输入的有效方法是什么?

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

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

我想将 n 行存储为 2d 向量,最好的方法是什么?

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];
    }
}

这就是我总是初始化一个二维向量并接受输入的方式。 我觉得没有比这更有效的了。

暂无
暂无

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

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