string substr(size_t pos = 0, size_t len = npos) const;
: 문자열의 pos 위치에서 len개의 문자를 복사하여 반환합니다.
pos가 문자열의 길이보다 크면 오류가 발생하고, pos 위치에서 len의 길이가 문자열을 초과할 경우는 npos까지 반환합니다.
<예시 코드>
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "toast";
cout << str.substr(1, 3);
return 0;
}
결과
