Aracılığıyla paylaş


basic_string::begin

Dizedeki ilk öğe adresleme bir yineleyici döndürür.

const_iterator begin( ) const;
iterator begin( );

Dönüş Değeri

İlk öğe sırası veya yalnızca boş bir sıra ötesinde adresleri rasgele erişim Yineleyici.

Açıklama

Dönüş değeri başlayan için atanmış bir const_iterator, string nesnesi değiştirilemez.Dönüş değeri başlayan atanmış bir Yineleyici, string nesnesi değiştirilebilir.

Örnek

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

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

   str1_Iter = str1.begin ( );
   cout << "The first character of the string str1 is: " 
        << *str1_Iter << endl;
   cout << "The full original string str1 is: " << str1 << endl;

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

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

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

Çıktı

The first character of the string str1 is: N
The full original string str1 is: No way out.
The first character of the modified str1 is now: G
The full modified string str1 is now: Go way out.
The string str2 is empty.

Gereksinimler

Başlık: <string>

Namespace: std

Ayrıca bkz.

Başvuru

basic_string Class