题目来源:CPP27 获取字符串长度
#include <iostream>
using namespace std;
int main() {
char str[100] = { 0 };
cin.getline(str, sizeof(str));
// write your code here......
int len=0;
char *p=str;
while(*p!='\0'){
len++;
p++;
}
cout<<len;
return 0;
}
#include <iostream>
using namespace std;
int main() {
char str[100] = { 0 };
cin.getline(str, sizeof(str));
char *p1=str;
while(*p1!='\0'){p1++;
}
cout<<p1-str<<endl; //地址相减得出中间元素个数
return 0;
}