Reputation: 155
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.
Upvotes: 0
Views: 3494
Reputation: 208323
hostIP = std::string(hostURL.begin(), std::string::const_iterator(colon));
You cannot create a std::string::const_iterator
from a pointer to a character. You should not try to mix C style string functions strchr
with C++ style std::string
as they don't mix well. Use std::string::find
to locate the :
and then std::string::substr
to create the hostIP
or else, use std::find
(algorithm) to get an iterator into the :
inside the string and use your current constructor.
Upvotes: 2