Udostępnij za pośrednictwem


basic_string::end

Zwraca iterację likwidującą lokalizacji przejmującej w ciągu ostatniego elementu.

const_iterator end( ) const;
iterator end( );

Wartość zwracana

Zwraca iteratora random access, likwidującą lokalizacji przejmującej w ciągu ostatniego elementu.

Uwagi

koniec jest często używany do testowania, czy osiągnął koniec ciągu jego iterację.Wartość zwracana przez celu nie należy usunąć odwołania.

Jeśli wartość zwracana przez end jest przypisany do const_iterator, nie można modyfikować obiekt string.Jeśli wartość zwracana przez end jest przypisany do iteratora, można zmodyfikować obiekt string.

Przykład

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

int main( ) 
{
   using namespace std;
   string str1 ( "No way out." ), str2;
   basic_string <char>::iterator str_Iter, str1_Iter, str2_Iter;
   basic_string <char>::const_iterator str1_cIter;

   str1_Iter = str1.end ( );
   str1_Iter--;
   str1_Iter--;
   cout << "The last character-letter of the string str1 is: " << *str1_Iter << endl;
   cout << "The full orginal string str1 is: " << str1 << endl;

   // end used to test when an iterator has reached the end of its string
   cout << "The string is now: ";
   for ( str_Iter = str1.begin( ); str_Iter != str1.end( ); str_Iter++ )
      cout << *str_Iter;
   cout << endl;

   // The dereferenced iterator can be used to modify a character
    *str1_Iter = 'T';
   cout << "The last character-letter of the modified str1 is now: "
        << *str1_Iter << endl;
   cout << "The modified string str1 is now: " << str1 << endl;

   // The following line would be an error because iterator is const
   // *str1_cIter = 'T';

   // For an empty string, end is equivalent to begin
   if ( str2.begin( ) == str2.end ( ) )
      cout << "The string str2 is empty." << endl;
   else
      cout << "The stringstr2  is not empty." << endl;
}
  
  
  
  

Wymagania

Nagłówek: <string>

Obszar nazw: std

Zobacz też

Informacje

basic_string Class