일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 315. Count of Smaller Numbers After Self
- 밴픽
- Generator
- Class
- t1
- attribute
- 109. Convert Sorted List to Binary Search Tree
- DWG
- 30. Substring with Concatenation of All Words
- LeetCode
- Substring with Concatenation of All Words
- data science
- 컴퓨터의 구조
- Convert Sorted List to Binary Search Tree
- Regular Expression
- 715. Range Module
- concurrency
- kaggle
- Protocol
- shiba
- Python Code
- iterator
- Decorator
- 파이썬
- Python Implementation
- Python
- 운영체제
- 프로그래머스
- 43. Multiply Strings
- 시바견
Archives
- Today
- Total
Scribbling
[C++] 전문가를 위한 C++ - Chapter 2 본문
1. String
substr(pos, len)
find(str)
replace(pos, len, str)
starts_with(str)
ends_with(str)
int main() {
string str{ "Hello!" };
if (str.find("!") != string::npos) {
cout << str << endl;
}
}
2. Number to String
int main() {
long double d{ 3.14L };
string s{ to_string(d) };
}
3. String to Number
int stoi(const string& str, size_t* idx=0, int base=10);
long stol(const string& str, size_t* idx=0, int base=10);
...
4. String_view
string_view is a new feature in C++17 - it is an efficient method to get a substring of the given string; it does not copy the string nor can modify it.
string_view func(string_view sv) {
return sv.substr(sv.rfind('.'));
}
int main() {
string filename{ "C:\\temp\\my file.txt" };
cout << func(filename) << endl;
cout << "string"s + func(filename).data() << endl;
}
5. format
int main() {
int i{ 10 };
auto s2{ format("Read {0} bytes from {1}", i, "file1.txt" )};
cout << s2 << endl;
}
'Computer Science > C++' 카테고리의 다른 글
[C++] find, deque, bfs, structured binding (0) | 2023.09.30 |
---|---|
[C++] Smart pointers (0) | 2023.09.30 |
[C++] 2d DP table with vector (0) | 2023.09.19 |
[C++] 전문가를 위한 C++ - Chapter 1 (0) | 2023.09.15 |
[C++] vector<vector<int>> sorting with comparator (0) | 2023.09.07 |