#include<iostream>
#include<string>
using namespace std;
int main() {
string s;
cin >> s;
const char * p = s.c_str();
int len = 0;
while (*p++)
len++;
cout << "the length of string :" << len << endl;
system("pause");
return 0;
}
计算字符串的长度
最新推荐文章于 2024-03-14 12:41:42 发布
本文介绍了一种使用C++计算字符串长度的方法。通过将输入的字符串转换为字符指针,并利用while循环遍历每个字符直至遇到空字符,从而计算出字符串的实际长度。
665

被折叠的 条评论
为什么被折叠?



