2012-05-04 5 views
0

MS Visual Studio 2005의 Windows에서 Openipmp 클라이언트를 실행 중입니다. 문서에 따르면 Visual Studio 6에서만 테스트되었지만 MS Visual Studio .NET. 내가 DRMPlugin를 컴파일하고 때은 'const char *'에서 'std :: _ String_const_iterator'로 변환 할 수 없습니다.

, 하나의 코드는 다음 오류를

error C2440: '<function-style-cast>' : cannot convert from 'const char *' 
to 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' 
     with 
     [ 
      _Elem=char, 
      _Traits=std::char_traits<char>, 
      _Alloc=std::allocator<char> 
     ] 
     No constructor could take the source type, or constructor overload resolution was ambiguous 

을주는 것은 누군가가 코드에 어떤 문제가 있는지 말해 줄 수 코드

bool OpenIPMPDOIContentInfoManager::ParseHostIPPort(const std::string& hostURL, 
    std::string& hostIP, int& hostPort) { 
    const char* colon = strchr(hostURL.data(), ':'); 
    if (colon == NULL) { 
    return false; 
    } 
    hostIP = std::string(hostURL.begin(), std::string::const_iterator(colon)); 
    hostPort = atoi(++colon); 
    return true; 
} 

에게 있습니다.

도와주세요.

+0

텍스트 블록을 코드로 표시하려면 텍스트 블록을 선택하고 {} 기호 (또는 Ctrl-K)를 눌러 버튼을 누릅니다. 코드 (및 가능한 오류)를 코드로 표시하면 읽기가 쉬워집니다. –

+0

David 님의 제안에 감사드립니다. 나는 명심할 것이다 :). –

답변

2
hostIP = std::string(hostURL.begin(), std::string::const_iterator(colon)); 

문자 포인터로 std::string::const_iterator을 만들 수 없습니다. C 스타일 문자열 함수 strchr과 C++ 스타일 std::string을 잘 섞어서 사용하지 마십시오. std::string::find을 사용하여 :을 찾은 다음 std::string::substr을 찾아 hostIP을 만들거나 std::find (알고리즘)을 사용하여 문자열 내부의 :에 반복기를 가져와 현재 생성자를 사용합니다.

+0

안녕하세요, David, 답변 해 주셔서 감사합니다. 앞에서 말했듯이 이것은 오픈 소스 코드입니다. 모든 코드는 이미 작성되었습니다. 난 그냥 컴파일하고있다. 당신의 제안에 따라이'const char * colon = std :: string :: find (hostURL.data(), ':'); ' #'(colon == NULL)) 'hostPort = std :: string :: substr (hostURL.begin(),''std :: string :: const_iterator (colon));' 'false를 반환합니다. 'hostPort = = atoi (++ 콜론); ' –

+0

나쁜 편집 죄송하지만 proeprly 쓸 수 없습니다. –

+0

하지만 여전히 오류가 있습니다. 몇 가지 샘플 코드를 작성해 주시겠습니까? –

관련 문제