I am trying to run a c++ code, which is a open source. And already tested visual studio 6 and .NET 2003. I am trying to run it on VS 2005. The code is this:-
error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
Conversion loses qualifiers
error C2440: '<function-style-cast>' : cannot convert from '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 second error is coming because const_iterator is using as a constructor.
Can anybody suggest what's wrong with the code. Is it bcoz of compiler?
Thanks in advance
hostURL.data() gives you a const char* so the const version of strchr will be called, returning a const char*. Change the type of colon to const char*.
std::string::const_iteratorcolon are you trying to cast a pointer into a std::string::const_iterator? Don't do that. You can use pointers as iterators so this should work: hostIP = std::string(hostURL.data(), colon);
thanks Peter for the reply.
I did what you have said. First error has gone. After changing hostip, now its giving following error
1 2 3 4 5 6 7
'std::basic_string<_Elem,_Traits,_Ax>::basic_string' : none of the 13 overloads could convert all the argument types
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
error C2039: 'cbegin' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
just wanted to mention that code was tested on visual 6 and .NET 2003. But i am running it on 2005 because of the unavailability of these two IDE.
I am not very much familiar with these type of c++ programming, but i feel that in 2005 const_iterators implementation has been changed. So it's not able to work on char pointer.
std::string::iterator p; // p is not referring to a valid element
*p = *colon; // so you should not try to dereference it.
// This is similar to how normal pointers work:
// You should not dereference dangling
// pointers and null pointers.
ohh, then please suggest me something. Because this code is compiling, that means the solution would be something like this only. Please suggest something.