0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[tips][cpp] vector配列の初期化

Last updated at Posted at 2024-10-05

※tips cpp集は、検索したことをcacheみたいに使用するためのmy備忘録です。

Vector配列の初期化

一次元配列

サイズのみの場合

要素数10個の配列を作ります。

int n = 10;
vector<int> a(n);

サイズと値で初期化する場合

要素数10個の配列を作ります。

値をfalseに指定された要素を10個作っています。

int n = 10;
bool flag = false;
vector<bool> a(n, flag);

二次元配列

1次元配列と同じようにします。

サイズのみの場合

10×20の配列を作ります。

int h = 10;
int w = 20;

vector<vector<int>> a(h, vector<int>(w));

サイズと値で初期化する場合

要素をfalseに持つ、10×20の配列を作ります。

int h = 10;
int w = 20;

vector<vector<bool>> a(h, vector<bool>(w, false));
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?