Aracılığıyla paylaş


basic_string::max_size

En fazla dize içerebilir karakter sayısını verir.

size_type max_size( ) const;

Dönüş Değeri

En fazla dize içerebilir karakter sayısı.

Notlar

Özel durum türü length_error sınıfı en büyük boyuttan daha büyük bir uzunluğa sahip bir dize bir işlemin ürettiği zaman atılır.

Örnek

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

int main( ) 
{
   using namespace std;
   string str1 ("Hello world");
   cout << "The original string str1 is: " << str1 << endl;

   // The size and length member functions differ in name only
   basic_string <char>::size_type sizeStr1, lenStr1;
   sizeStr1 = str1.size ( );
   lenStr1 = str1.length ( );

   basic_string <char>::size_type capStr1, max_sizeStr1;
   capStr1 = str1.capacity ( );
   max_sizeStr1 = str1.max_size ( );

   // Compare size, length, capacity & max_size of a string
   cout << "The current size of original string str1 is: " 
        << sizeStr1 << "." << endl;
   cout << "The current length of original string str1 is: " 
        << lenStr1 << "." << endl;
   cout << "The capacity of original string str1 is: "
        << capStr1 << "." << endl;
   cout << "The max_size of original string str1 is: " 
        << max_sizeStr1 << "." << endl << endl;

   str1.erase ( 6, 5 );
   cout << "The modified string str1 is: " << str1 << endl;

   sizeStr1 = str1.size ( );
   lenStr1 = str1.length ( );
   capStr1 = str1.capacity ( );
   max_sizeStr1 = str1.max_size ( );

   // Compare size, length, capacity & max_size of a string
   // after erasing part of the original string
   cout << "The current size of modified string str1 is: " 
        << sizeStr1 << "." << endl;
   cout << "The current length of modified string str1 is: " 
        << lenStr1 << "." << endl;
   cout << "The capacity of modified string str1 is: "
        << capStr1 << "." << endl;
   cout << "The max_size of modified string str1 is: " 
        << max_sizeStr1 << "." << endl;
}

Örnek Çıktı

X 86 için aşağıdaki çıktıdır.

The original string str1 is: Hello world
The current size of original string str1 is: 11.
The current length of original string str1 is: 11.
The capacity of original string str1 is: 15.
The max_size of original string str1 is: 4294967294.

The modified string str1 is: Hello 
The current size of modified string str1 is: 6.
The current length of modified string str1 is: 6.
The capacity of modified string str1 is: 15.
The max_size of modified string str1 is: 4294967294.

Gereksinimler

Başlık: <string>

Namespace: std

Ayrıca bkz.

Başvuru

basic_string Class