Hello,
I've had some problems converting a string into a char. I've tried many, many things, but it didn't seem to work.
I'll post the code below:
char filename[1024];
char* url;
string sUrl;
HINTERNET hINet, hFile;
hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if ( !hINet )
{
return false;
}
//http://www.tibia.com/statistics/?subtopic=highscores&world=Aldora&list=magic&page=10
int Page = 0;
while(Page < 12)
{
sUrl+="http://www.tibia.com/statistics/?subtopic=highscores&world=";
sUrl+=Server;
sUrl+="&list=";
sUrl+=Skill;
sUrl+="&page=";
sUrl+=Page;
Page+=1;
url = sUrl.c_str();
cout << url << endl;
hFile = InternetOpenUrl( hINet, (char*)sUrl, ULL, 0, 0, 0 );
//The rest of the loop, no troubles here.
As you can see, I'm making a string that will contain the URL, I place the URL in it and then want to convert it to a char*.
I really tried about everything.
The URL doesn't neccesarely have to be a string, but I thought that would be the easiest way.
The errors that I get are:
Compiling...
TibiaName.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\TibiaName\TibiaName.cpp(169) : error C2440: '=' : cannot convert from 'const char *' to 'char *'
Conversion loses qualifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\TibiaName\TibiaName.cpp(173) : error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
TibiaName.exe - 2 error(s), 0 warning(s)
line 169 is url = sUrl.c_str();
and line 173 is hFile = InternetOpenUrl( hINet, (char*)sUrl, ULL, 0, 0, 0 );
Greetz, Eddy
Edit: The error is in the strcpy() line, weird thing is that if I remove that line (put // before it) it still crashes. I will try to find out why.