ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [c++] 배열 초기화
    아무거나적어~ 2022. 12. 21. 17:47

    1D vector

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        vector<int> v(10); // 처음 초기화 할 때는 vector<int> v(10, 123); 이런식으로 가능
        fill_n(v.begin(), 10123);
        cout << v[0<< endl;
        cout << v[9<< endl;
     
        return 0;

    2D vector

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        vector v(10vector<int>(20)); // 처음 초기화 할 때는 vector v(10, vector<int>(20, 123)); 이런식으로 가능
        fill_n(v.begin(), 10vector<int>(20123));
        cout << v[0][0<< endl;
        cout << v[9][19<< endl;
     
        return 0;

    1D array

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int edge[10];
        fill_n(edge, size(edge), 123);
        cout << edge[0<< endl;
        cout << edge[9<< endl;
     
        return 0;

    2D array

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int edge[10][20];
        fill_n(edge[0], 10*20123);
        cout << edge[0][0<< endl;
        cout << edge[9][19<< endl;
     
        return 0;

     

    '아무거나적어~' 카테고리의 다른 글

    c++ vs python  (0) 2022.12.31
    수열 규칙 찾아주는 사이트  (0) 2022.12.23
    c++ 의 매력??  (0) 2022.12.21
    [c++] size vs sizeof  (0) 2022.12.21
    file을 이용해서 입출력 받고자 할 때  (0) 2022.12.14

    댓글

Designed by Tistory.