此函数用于返回以字节为单位的字符串长度。它定义了符合字符串对象内容的实际字节数,不一定等于容量。
考虑一个名为'str'的字符串对象。要计算此字符串对象的大小,其语法为:
str.size()
此函数返回字符串对象中存在的字符数。
#include<iostream> using namespace std; int main() { string str ="Welcome to the learnfk tutorial"; int size = str.size(); cout << "length of the string is :" <<size; return 0; }
输出:
length of the string is : 30
在此示例中,str是一个字符串对象,包含值" Welcome to the learnfk tutorial"。我们使用'size'函数计算字符串的长度。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕