250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- update
- Node
- Chunk
- log4j2
- current_date
- JavaScript
- eslint
- regex
- java
- Regular expression
- Spring Batch
- REACTJS
- Effective Java 3/e
- 퀵소트
- spring cloud
- expire_logs_days
- 정규표현식
- mysql 5.5
- spring
- npm
- git
- REACT
- try catch
- upgrade
- Effective Java
- Express
- MySQL
- migration
- log_bin
- nodejs
Archives
- Today
- Total
내 세상
[C++] C++11/C++17 에서의 반복문/제어문 본문
728x90
반응형
C++11 반복문
#include <iostream>
int main()
{
int x[10] = { 1,2,3,4,5,6,7,8,9,10 };
// 전통적인 for문
for (int i = 0; i < 10; i++)
std::cout << x[i] << std::endl;
// c++11의 새로운 for문 : java, C#언어의 foreach와 동일
// 배열뿐 아니라 c++ 표준 라이브러리 (,list, vector 등 모두 가능)
for (int n : x)
{
std::cout << n << std::endl;
}
}
C++17 제어문
int foo() { return 0; }
int main()
{
int ret = foo();
if (ret == 0) {
}
// C++ 17 새로운 제어문 : int if 라는 문법
if (int ret2 = foo(); ret2 == 0) {
// ret2 활용
}
switch (int n = foo(); n) {
case 1:break;
case 2:break;
}
bool b1 = n > 10; // 크기 비교
int n1 = n <=> 10; // 우주선 연산자!!! C++ 20
}
C++20 에서의 우주선 연산자 (operator <=>)
- a <=> b
- a - b > 0, 1
- a - b == 0, 0
- a - b < 0, -1
728x90
반응형
'Language > C/C++' 카테고리의 다른 글
[C++] nullptr (0) | 2020.01.02 |
---|---|
[C++] C++스타일의 캐스팅 (0) | 2020.01.02 |
[C++] 함수 (0) | 2020.01.02 |
[C++] 표준입출력, 변수 선언 (0) | 2020.01.02 |
[C++] namespace, std (0) | 2020.01.02 |