获取字符串长度

来源:互联网 发布:在线视频源码 编辑:程序博客网 时间:2024/05/15 00:36

答案如下:

#include <iostream>using namespace std;int str_len(char *str);int main(){    char *str = new char[100];    cin>>str;    cout<<str_len(str);    delete str;    return 0;}int str_len(char *str){    int i=0;    while(str[i]!='\0')    {        i++;}    return i;} 

注:用户输入的字符串末尾会加\0,包括string类型的字符串

0 0
原创粉丝点击