TIL
221229 오늘의 삽질
독서왕뼝아리
2022. 12. 29. 10:00
#include<string>
using namespace std;
int main() {
string str ="aabbbcccddd";
str.substr(1,3); // abb
}
위와 같이 c++에서 string 자료형을 substr 할 수 있다는 것을 익히 알고 있을 것이다.
매개변수가 Python의 slicing처럼 [시작 인덱스 : 마지막 인덱스) 인 줄 알았다.
basic_string substr(
const size_type _Off = 0, const size_type _Count = npos) const {
// return [_Off, _Off + _Count) as new string
return basic_string(*this, _Off, _Count, get_allocator());
}
std::substr(시작 인덱스, 그 뒤로 자를 개수)
std::substr(마지막 인덱스) // 0부터 시작해 마지막 인덱스까지
std::size_t pos = str.find( param ); // 매개변수의 위치 반환
기본적인 문법에서 시간 버리지 말자. 제발