这是我的代码:

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();
}


其中allfiles.txt(内容):

http://www.xxx.com/index1.html
http://www.xxx.com/index2.html


href []的值类似于:{index1.html,index2.html,index3.html ...}

我的错误讯息:

file.cpp:XX: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int system(const char*)’

最佳答案

函数'system'接受'const char *'作为参数,但是您给了它一个std :: string。尝试

system(dl.c_str());

09-07 07:47