2010-11-25 5 views
0

voici mon code:problème avec bash (Système-> wget) commande en C++

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

Lorsque le allfiles.txt (le contenu):

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

Où href [] valeurs comme: {index1.html, index2.html, index3.html ...}

Mon message d'erreur:

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

Avez-vous vraiment jamais rencontré 'std :: string :: c_str()'? –

+0

@ignacio: Je pense que je comprends maintenant. Désolé pour ce genre de question Noob. Je viens de commencer C++ – popurity09

Répondre

3

La fonction « système » prend un «const char * comme argument, mais vous lui avez donné un std :: string. Essayez

system(dl.c_str()); 
2

system veut un const char * argument, de sorte que vous devez appeler dl.c_str() pour obtenir un char * aux données std::string.

system(dl.c_str()); 
1

system() ne connaissez rien aux types C++. Vous devez donner char* comme ceci:

system(dl.c_str());