C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ String size()

C++ String size()

此函数用于返回以字节为单位的字符串长度。它定义了符合字符串对象内容的实际字节数,不一定等于容量。

语法

请考虑一个名为'str'的字符串对象。要计算此字符串对象的大小,其语法应为:
str.size()

参数

此函数不包含任何参数。

返回值

此函数返回字符串对象中存在的字符数。

示例1

#include<iostream>
using namespace std;
int main()
{
string str ="Welcome to the lidihuo tutorial";
int size = str.size();
cout << "length of the string is :" <<size; 
return 0;
}
输出:
length of the string is : 34
在此示例中,str是一个字符串对象,包含值" Welcome to the lidihuo tutorial"。我们使用'size'函数计算字符串的长度。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4