Notice
                              
                            
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
                            Tags
                            
                        
                          
                          - 자료구조
- 시스템프로그래밍
- LineTracer
- Stack
- 아두이노 소스
- Arduino
- html
- arduino compiler
- directx
- 라인트레이서
- Deque
- Algorithm
- 컴퓨터 그래픽스
- 아두이노
- 수광 소자
- queue
- list
- c++
- Visual Micro
- priority_queue
- Array
- stl
- map
- 아두이노 컴파일러
- WinAPI
- 통계학
- set
- 운영체제
- vector
- C언어
                            Archives
                            
                        
                          
                          - Today
- Total
Kim's Programming
STL(Standard Template Library) - Container - Array 본문
Array는 기존에 C언어를 배우면서 배우는 일반적인 배열과 같은 배열입니다. STL의 Array를 이용하기 위해서는 아래 두개를 인클루드 해야합니다.
| 1 2 3 | #define Max_size 10 #include<iostream> #include<array> | cs | 
Array는 다음과 같이 선언하게됩니다.
| 1 | std::array<int, Max_size> Array = { 1,2,3,4,5,6,7,8,9, 10 }; | cs | 
std::array<형식,최대크기> 이름 순으로 선언을 하게됩니다.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #define Max_size 10 #include<iostream> #include<array> void print(std::array<int,Max_size> Target_Array) {     for (std::array<int, Max_size>::iterator IterPos = Target_Array.begin(); IterPos != Target_Array.end(); ++IterPos)         std::cout << *IterPos << " ";     std::cout << std::endl; } void main() {     std::array<int, Max_size> Array = { 1,2,3,4,5,6,7,8,9, 10 };     std::array<int, Max_size> Array_copy = { 10,9,8,7,6,5,4,3,2,1 };     std::array<int, Max_size>::iterator Iter;     //at(x) function return value that locate in x(th) array     std::cout << std::endl << "assign(x)" << std::endl;     std::cout<<"assign(3) ---> "<<Array.at(3)<<std::endl;     //back() function return last value     std::cout << std::endl << "back()" << std::endl;     std::cout << "back() ---> " << Array.back() << std::endl;     //begin() function return Iterator that point first value     std::cout << std::endl << "begin()" << std::endl;     std::cout << "begin() ---> " << *Array.begin() << std::endl;     //cbegin() function return const Iterator that point first value     std::cout << std::endl << "cbegin()" << std::endl;     std::cout << "cbegin() ---> " << *Array.cbegin() << std::endl;     //cend() function return const Iterator that point next to last value     std::cout << std::endl << "cend()" << std::endl;     std::cout << "cend() ---> " << *(--Array.cend()) << std::endl;     //crbegin() function return const Iterator that point first value(reverse)     std::cout << std::endl << "crbegin()" << std::endl;     std::cout << "crbegin() ---> " << *Array.crbegin() << std::endl;     //crend() function return const Iterator that point next to last value(reverse)     std::cout << std::endl << "crend()" << std::endl;     std::cout << "crend() ---> " << *(--Array.crend()) << std::endl;     //data() function return pointer that point first array     std::cout << std::endl << "data()" << std::endl;     std::cout << "data() ---> " << Array.data() << std::endl;     //if Array is empty, empty() function return true     std::cout << std::endl << "empty()" << std::endl;     if (Array.empty())         std::cout << "Array is empty" << std::endl;     else         std::cout << "Array is not empty" << std::endl;     //end() function return const Iterator that point next to last value     std::cout << std::endl << "end()" << std::endl;     std::cout << "end() ---> " << *(--Array.end()) << std::endl;     //front() function return first value     std::cout << std::endl << "front()" << std::endl;     std::cout << "front() ---> " << Array.front() << std::endl;     //max_size() function return current Max_size     std::cout << std::endl << "max_size()" << std::endl;     std::cout << "max_size() ---> " << Array.max_size() << std::endl;     //operator[x] means x(th) array     std::cout << "operator []" << std::endl;     std::cout <<"Array[4] --->"<< Array[4] << std::endl;     //rbegin() function return Iterator that point first value(reverse)     std::cout << std::endl << "rbegin()" << std::endl;     std::cout << "rbegin() ---> " << *Array.rbegin() << std::endl;     //rend() function return Iterator that point next to last value(reverse)     std::cout << std::endl << "rend()" << std::endl;     std::cout << "rend() ---> " << *(--Array.rend()) << std::endl;     //size() function return current size     std::cout << std::endl << "size()" << std::endl;     std::cout << "size() ---> " << Array.size() << std::endl;     //x1.swap(x2) function swap x1 and x2     std::cout << "Previous Array ---> "; print(Array);     std::cout << "Previous Array_Copy ---> "; print(Array_copy);     Array.swap(Array_copy);     std::cout << "After Array ---> "; print(Array);     std::cout << "After Array_Copy ---> "; print(Array_copy);     //fill(x) function fill all arraies with 'x'     std::cout << std::endl << "fill(x)" << std::endl;     std::cout << "Previous Array ---> "; print(Array);     Array.fill(3);     std::cout << "After Array ---> "; print(Array);     //assign(x) function assign 'x' in all arries     std::cout << std::endl << "assign(x)" << std::endl;     std::cout << "Previous Array ---> "; print(Array);     Array.assign(7);     std::cout << "After Array ---> "; print(Array); } | cs | 
전체소스를 이용하여 하나하나 함수를 알아보겠습니다.(함수를 누르면 상세 설명으로 넘어갑니다.)
- assign(x)
 assign(x)함수는 선언한 배열에 모든 값들을 x로 채우는 함수입니다.
- back()
 back() 함수는 배열에서의 가장 마지막에 있는 값을 리턴합니다.
- begin()
 begin()함수는 첫 번째 값을 가리키고 있는 이터레이터를 리턴합니다.
- cbegin()
 cbegin()함수는 첫 번째 값을 가리키고 있는 const 이터레이터를 리턴합니다.
- cend()
 cend()함수는 마지막 값 다음 칸을 가리키는 const 이터레이터를 리턴합니다.
- crbegin()
 crbegin()함수는 역방향으로 첫 번째 값을 가리키고 있는 const 이터레이터를 리턴합니다.
- crend()
 crend()함수는 역방향으로 가장 마지막 값 다음 칸을 가리키는 const 이터레이터를 리턴합니다.
- data()
 data()함수는 Array의 첫 번째 배열의 주소를 리턴합니다.
- empty()
 empty()함수는 Array가 비었는지 확인합니다. 비어있다면 true를 그렇지 않으면 false를 리턴합니다.
- end()
 end()함수는 Array에 마지막 값 다음을 가리키는 이터레이터를 리턴합니다.
- front()
 front()함수는 Array에서 가장 첫 값을 리턴합니다.
- max_size()
 max_size() 함수는 배열의 최대 크기를 리턴합니다.
- Operator []
 [x] 연산자는 x+1번째 Array의 값을 의미합니다.
- rbegin()
 rbegin()함수는 역방향으로 첫 번째 값을 가리키고 있는 이터레이터를 리턴합니다.
- rend()
 rend()함수는 역방향으로 마지막 값의 다음을 다리키고 있는 이터레이터를 리턴합니다.
- size()
 size()함수는 현재의 배열의 사이즈를 리턴합니다.
- swap(Array)
 swap 함수는 호출한 배열과 괄호속의 배열 두 배열의 값을 완전히 교체해 줍니다.
- fill(x)
 x로 배열의 모든 내용을 채웁니다.
- at(x)
 x+1번째 값을 리턴합니다.
'STL - Container' 카테고리의 다른 글
| STL(Standard Template Library) - Container - Queue (0) | 2016.01.27 | 
|---|---|
| STL(Standard Template Library) - Container - Stack (0) | 2016.01.27 | 
| STL(Standard Template Library) - Container - Vector (0) | 2016.01.22 | 
| STL(Standard Template Library) - Container - List (0) | 2016.01.22 | 
| STL(Standard Template Library) (0) | 2015.12.20 |