2010-11-25 38 views
0

這裏的bash(系統 - >的wget)命令是我的代碼:問題的在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(); 
} 

凡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*)’ 
+2

你真的沒有遇到`std :: string :: c_str()`嗎? – 2010-11-25 17:43:16

回答

3

功能「系統」需要「爲const char *」的說法,但你給它一個的std :: string。嘗試

system(dl.c_str()); 
2

system想要一個const char *參數,因此您必須致電dl.c_str()以獲得char *std::string的數據。

system(dl.c_str()); 
1

system()對C++類型一無所知。你必須給它char*這樣的:

system(dl.c_str());