here is my code:
string line;
ifstream toOpen;
toOpen.open("allfiles.txt", ios::in);
int fileCounter=0;
if(toOpen.is_open()){
while(!toOpen.eof()){
getline(toOpen,line);
string dl = "wget -q -E -O superman/" + href[0] + " " + line;
//cout << dl << endl;
fileCounter++;
system(dl);
}
toOpen.close();
}
Where the allfiles.txt (the content):
http://www.xxx.com/index1.html
http://www.xxx.com/index2.html
Where 开发者_JAVA技巧href[] values are like: {index1.html, index2.html, index3.html ...}
My error message:
file.cpp:XX: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int system(const char*)’
The function 'system' takes a 'const char *' as argument but you gave it an std::string. Try
system(dl.c_str());
system
wants a const char *
argument, so you have to call dl.c_str()
to get a char *
to the std::string
's data.
system(dl.c_str());
system()
know nothing about C++ types. You have to give it char*
like this:
system(dl.c_str());
精彩评论