2012-12-04 2 views
0
#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; 
} 

이 내 코드, 그리고 내가 GCC + 엑스 코드를 사용 .... 항상 존재하는 이유는 두 CString을를 사용하는, 내가 나 strlen 찾을 수없는 이야기 ...어떤 일이 내가 나 strlen 찾을 수없는 이유를 포함 문제가()

답변

5

strlenconst char*에 적용되고 string에는 적용되지 않습니다. 대신 str.length()을 사용할 수 있습니다.

0

c 문자열과 C++ 문자열 lib는 서로 매우 다르므로 혼합 할 수 없습니다. 이에 대한 수정은 C 문자열로 문자열을 처리하는 것입니다 :

strlen(str.c_str()); //convert string into char * 

C++ 문자열을 보유하고 있으며 C 코드와 C의 방법에 쉽게 휴대 내부 C 문자열.

또한 cstringstring.h이 같은 파일을 참조 점에 유의하는 것이 좋을 것이다는 C는 C++ libs와 및 C libs와를 구성하는 C++ 방법이다

#include <cstdio> 
#include <cstdlib> //could be stdlib.h, but used to show that this lib is a c lib 
#include <csting> //same as string.h 
#include <string> //c++ string lib 
관련 문제