일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Protocol
- Regular Expression
- 파이썬
- LeetCode
- data science
- 30. Substring with Concatenation of All Words
- iterator
- Python
- 밴픽
- 109. Convert Sorted List to Binary Search Tree
- Python Code
- DWG
- kaggle
- Substring with Concatenation of All Words
- concurrency
- Python Implementation
- 운영체제
- Generator
- Decorator
- 시바견
- 프로그래머스
- attribute
- 715. Range Module
- 315. Count of Smaller Numbers After Self
- t1
- 컴퓨터의 구조
- 43. Multiply Strings
- Convert Sorted List to Binary Search Tree
- Class
- shiba
Archives
- Today
- Total
Scribbling
[C++] 전문가를 위한 C++ - Chapter 1 본문
1. import
C++20 has a new feature called "module" - replacing the conventional header file mechanism.
#pragma once
import <iostream>;
import <array>;
import <vector>;
int main() {
std::cout << "Hello World" << std::endl;
}
If you have trouble with "Importing modules" in Visual Studio, https://stackoverflow.com/questions/64877559/cant-use-iostream-as-module-in-c20-visual-studio
2. Format
format is very similar to Python formats.
#pragma once
import <iostream>;
import <format>;
int main() {
std::cout << std::format("format example: {}", 29) << std::endl;
}
3. numeric_limits
numeric_limits in <limits> provides numeric limits.
int main() {
std::cout << std::numeric_limits<int>::max() << std::endl;
std::cout << std::numeric_limits<int>::min() << std::endl;
}
4. Zero Initializer
int main() {
float float1{};
int int1{};
int* intptr1{};
std::cout << float1 << std::endl;
std::cout << int1 << std::endl;
std::cout << intptr1 << std::endl;
}
5. Three-way comparison operator
int main() {
int i{ 29 };
strong_ordering result{ i <=> 29 };
cout << (result == strong_ordering::less) << endl;
cout << (result == strong_ordering::greater) << endl;
cout << (result == strong_ordering::equal) << endl;
}
6. Optional
optional<int> func1(bool flag) {
if (flag) {
return 29;
}
return nullopt;
}
int main() {
optional<int> ret = func1(true);
if (ret) {
cout << ret.value() << endl;
}
}
7. Designated Initializer
struct Employee {
char firstInitial;
char lastInitial;
int employeeNumber;
int salary{ 75000 };
};
int main() {
Employee employee{
.firstInitial = 'H',
.lastInitial = 'C',
.employeeNumber = 0,
.salary = 200000,
};
}
8. constexpr
C++ has a constant expression; constant expressions are evaluated during compile time.
constexpr int getInt() { return 29; }
int main() {
int array[getInt()];
}
'Computer Science > C++' 카테고리의 다른 글
[C++] 전문가를 위한 C++ - Chapter 2 (1) | 2023.09.21 |
---|---|
[C++] 2d DP table with vector (0) | 2023.09.19 |
[C++] vector<vector<int>> sorting with comparator (0) | 2023.09.07 |
[C++] priority queue (pair<int, pair<int, int>>), minheap (0) | 2023.09.02 |
[C++] vector sum, dp table with vector (0) | 2023.09.02 |