仅使用1行c ++初始化2d向量 [英] initializing 2d vector using only 1 line c++
本文介绍了仅使用1行c ++初始化2d向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够在创建它的同一行中初始化一个int的二维矢量.
I need to be able to initialize a 2D vector of int's in the same line in which I create it.
更具体地说,我必须创建一个 3x2 大小的2D向量,并仅使用 1行代码将其所有值设置为0.
To be more specific, I have to create a 3x2 size 2D vector and set all of it's values to 0 using only 1 line of code.
有没有一种方法可以在不使用for循环和几行代码的情况下完成?
Is there a way this can be done without using a for loop and several lines of code?
推荐答案
尝试一下:
std::vector<std::vector<int>> twoDimVector(3, std::vector<int>(2, 0));
这篇关于仅使用1行c ++初始化2d向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文