祝大家rp++ 2021-08-19 18:07 采纳率: 80%
浏览 32
已结题

string类型求字符串长度错误了

//我是初学者
#include <bits/stdc++.h>
using namespace std; 
int main()
{
    string s;
    cin>>s;
    int len=strlen(s);
    cout<<len;
    return 0;
}
  • 写回答

1条回答 默认 最新

  • 诺er~ 2021-08-19 18:08
    关注
    
    #include <bits/stdc++.h>
    using namespace std; 
    int main()
    {
        string s;
        cin>>s;
        int len=s.length();//strlen是求字符数组长度的
        cout<<len;
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月27日
  • 已采纳回答 8月19日
  • 创建了问题 8月19日