일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- react native 타입스크립트
- 싸이월드
- react native mac
- javascript
- Expo
- 스탠실 버퍼 튜토리얼
- 스탠실 버퍼 시작
- node.js
- C++
- unity stencil buffer
- react-native
- react native typescript navigation
- 리액트 네이티브 맥
- react native
- react
- react native typescript navigate
- 벡터와 리스트의 차이
- cyworld
- html
- stencil buffer
- c++ using
- 스탠실 버퍼 사용
- react native typescript
- c++ 정보은닉
- react native accessible
- react native ios 기기 연결
- CSS
- node
- 리액트 네이티브 설치 오류
- GitHub
Archives
- Today
- Total
혀니의 이거저거 뿌시기
<algorithm> 헤더의 sort와 list.sort 본문
728x90
[c++]리스트 sort 하는 방법 (tistory.com)
[c++]리스트 sort 하는 방법
C++ #include #include int main() { std::list lst; lst.push_back(5); lst.push_back(1); std::sort(lst.begin(), lst.end()); return 0; } 당연하다는 듯이 이런 코드를 작성한 적이 있는데 sort 부분에서 에러가 뜬다. 이유는 아래와
blossoming-man.tistory.com
#include <algorithm>
#include <list>
int main() {
std::list<int> lst;
lst.push_back(5);
lst.push_back(1);
std::sort(lst.begin(), lst.end());
return 0;
}
-> 컴파일 에러
원인: algorithm 헤더의 sort함수는 매개변수로 오는 반복자가 반드시 RandomAccessIterator(임의 접근 반복자) 타입이어야 함
리스트는 반복자가 BidirectionalIterator(순차 접근 반복자) 타입이므로 이를 쓸 수 없음.
아래와 같이 수정해야 함
#include <list>
int main() {
std::list<int> lst;
lst.push_back(5);
lst.push_back(1);
lst.sort();
return 0;
}
반복자에 대한 설명
코딩교육 티씨피스쿨
4차산업혁명, 코딩교육, 소프트웨어교육, 코딩기초, SW코딩, 기초코딩부터 자바 파이썬 등
tcpschool.com
728x90
'CS > C++' 카테고리의 다른 글
C++ template 장단점 (0) | 2023.12.14 |
---|---|
c++ 캐스팅 (0) | 2023.12.14 |
map과 unordered_map 차이 (0) | 2023.12.13 |
상등성과 동등성 차이 (0) | 2023.12.13 |
오버로딩과 오버라이딩의 차이 (0) | 2023.12.13 |