다음을 통해 공유


basic_string::substr

지정 된 위치에서 시작 하는 문자열에서에서 부분 문자열의 최대 문자 수를 복사합니다.

basic_string<CharType, Traits, Allocator> substr(
    size_type _Off = 0,
    size_type _Count = npos
) const;

매개 변수

  • _Off
    인덱스에서 문자열의 복사본을 기본값 0으로 구성 되어 있는 위치에 있는 요소를 찾는.

  • _Count
    있을 경우 복사할 문자의 수입니다.

반환 값

부분 문자열 개체 요소를 첫 번째 인수에서 지정한 위치에서 시작 하는 문자열 피연산자의 복사본입니다.

예제

// basic_string_substr.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   string  str1 ("Heterological paradoxes are persistent.");
   cout << "The original string str1 is: \n " << str1
        << endl << endl;

   basic_string <char> str2 = str1.substr ( 6 , 7 );
   cout << "The substring str1 copied is: " << str2
        << endl << endl;
   
   basic_string <char> str3 = str1.substr (  );
   cout << "The default substring str3 is: \n " << str3
        <<  "\n which is the entire original string." << endl;
}
  
  
  

요구 사항

헤더: <string>

네임 스페이스: std

참고 항목

참조

basic_string Class