-
[c++] 배열 초기화아무거나적어~ 2022. 12. 21. 17:47
1D vector
123456789101112#include <bits/stdc++.h>using namespace std;int main(){vector<int> v(10); // 처음 초기화 할 때는 vector<int> v(10, 123); 이런식으로 가능fill_n(v.begin(), 10, 123);cout << v[0] << endl;cout << v[9] << endl;return 0;}cs2D vector
123456789101112#include <bits/stdc++.h>using namespace std;int main(){vector v(10, vector<int>(20)); // 처음 초기화 할 때는 vector v(10, vector<int>(20, 123)); 이런식으로 가능fill_n(v.begin(), 10, vector<int>(20, 123));cout << v[0][0] << endl;cout << v[9][19] << endl;return 0;}cs1D array
123456789101112#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;}cs2D array
123456789101112#include <bits/stdc++.h>using namespace std;int main(){int edge[10][20];fill_n(edge[0], 10*20, 123);cout << edge[0][0] << endl;cout << edge[9][19] << endl;return 0;}cs'아무거나적어~' 카테고리의 다른 글
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