I am running Openipmp client on windows on MS visual studio 2005. Though according to document it was tested only on visual studio 6 and MS visual studio .NET.
when i am compiling DRMPlugin, one piece of code giving error
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
Here is the code
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;
}
Can somebody tell me what is wrong with the code.
Please help.
You cannot create a
std::string::const_iteratorfrom a pointer to a character. You should not try to mix C style string functionsstrchrwith C++ stylestd::stringas they don’t mix well. Usestd::string::findto locate the:and thenstd::string::substrto create thehostIPor else, usestd::find(algorithm) to get an iterator into the:inside the string and use your current constructor.