包含有什么问题,为什么我找不到strlen()

sta*_*ver 0 c++

#include "Q1-VerifyUniqueCharInString.h"
#include <cstring>
#include <stdio.h>
#include <string.h>

using namespace std;


bool isUniqueChar(string str)
{

    int length=strlen(str),i=0;
    bool tab[] = new bool[length];
    if (length > 0xff) {
        return false;
    }
    for (; i<length;++i) {
        if (str[i]) {
            return false;
        }
        tab[str[i]]=true;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码,我使用gcc + xcode ....为什么总是告诉我找不到strlen,我同时使用cstring和string.h ...

Luc*_*ore 5

strlen适用于a const char*,而不适用于a string.您可以(而且应该)使用str.length().