다음을 통해 공유


basic_string::difference_type

동일한 문자열 안에서 요소를 참조하는 두 반복기 사이의 차이를 제공하는 형식입니다.

typedef typename allocator_type::difference_type difference_type;

설명

The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence.

For type string, it is equivalent to ptrdiff_t.

예제

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

int main( ) 
{
   using namespace std;
   string str1 ( "quintillion" );
   cout << "The original string str1 is: " << str1 << endl;
   basic_string <char>::size_type indexChFi, indexChLi;

   indexChFi = str1.find_first_of ( "i" );
   indexChLi = str1.find_last_of ( "i" );
   basic_string<char>::difference_type diffi = indexChLi - indexChFi;

   cout << "The first character i is at position: "
        << indexChFi << "." << endl;
   cout << "The last character i is at position: "
        << indexChLi << "." << endl;
   cout << "The difference is: " << diffi << "." << endl;
}
  

요구 사항

헤더: <string>

네임스페이스: std

참고 항목

참조

basic_string 클래스