當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ String max_size()用法及代碼示例

由於已知係統,此函數返回字符串可以達到的最大長度。

用法

考慮一個字符串 str。語法是:

str.max_size();

參數

它不包含任何參數。

返回值

此函數返回字符串可以達到的最大長度。

例子1

讓我們看一個簡單的例子。

#include<iostream>
using namespace std;
int main()
{
string str = "Hello world";
cout<<"String is:" <<str<<'\n';
cout<<"Maximum size of the string is:"<<str.max_size();
return 0;
}





相關用法


注:本文由純淨天空篩選整理自 C++ String max_size()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。