일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- union find
- String
- binary search
- 이진탐색
- MYSQL
- Two Points
- Dijkstra
- Trie
- 그래프
- 스토어드 프로시저
- Brute Force
- 다익스트라
- Hash
- Stored Procedure
- SQL
- DP
- two pointer
Archives
- Today
- Total
codingfarm
C++ 문자열 snippet codes 본문
1. split
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> split(const string& str, char delimiter) {
vector<string> result;
size_t start = 0; // 시작 인덱스
size_t end;
while ((end = str.find(delimiter, start)) != string::npos) {
result.push_back(str.substr(start, end - start)); // 부분 문자열 추출
start = end + 1; // 다음 시작 지점으로 이동
}
// 마지막 토큰 처리
result.push_back(str.substr(start));
return result;
}
int main() {
string text = "apple,banana,grape";
vector<string> tokens = split(text, ',');
for (const string& word : tokens) {
cout << word << endl;
}
return 0;
}
python의 split을 C++로 구현한 함수.
2. stoi
문자열을 정수 타입으로 변환하는 함수이다.
int num = stoi("65");
Comments