Category Archives: C++

C++ – Initialize a two-dimensional vector in C++

1. init two-dimensional with 0 and resize

1
2
3
4
5
6
7
8
9
vector<vector<int>> c(n, vector<int>(m, 0));
 
resize:
// instantiate vector object of type std::vector<int>
std::vector<std::vector<int>> matrix;
 
// resize the vector to M elements of type std::vector<int>,
// each having size N and given default value
matrix.resize(M, std::vector<int>(N, default_value));

2. init with default value

1
2
3
4
5
6
vector<vector<int>> accounts
    {
        {1, 5},
        {7, 3},
        {3, 5}
    };

GCC – Dump all Macro defined in GCC

$ gcc -E -dM – < /dev/null

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
#define __SSP_STRONG__ 3
#define __DBL_MIN_EXP__ (-1021)
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
#define __FLT_MIN__ 1.17549435082228750797e-38F
#define __GCC_IEC_559_COMPLEX 2
#define __UINT_LEAST8_TYPE__ unsigned char
#define __SIZEOF_FLOAT80__ 16
#define __INTMAX_C(c) c ## L
#define __CHAR_BIT__ 8
#define __UINT8_MAX__ 0xff
#define __WINT_MAX__ 0xffffffffU
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __SIZE_MAX__ 0xffffffffffffffffUL
#define __WCHAR_MAX__ 0x7fffffff
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __DBL_DENORM_MIN__ ((double)4.94065645841246544177e-324L)
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
....