2010-11-25 3 views
0

中(システム - > 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(コンテンツ):hrefの[]の値がある

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

以下のような:{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()'に出くわしたことはありませんか? –

+0

@ignacio:私は今それを得ると思います。このような質問には申し訳ありません。私はちょうどC++を始めた – popurity09

答えて

3

関数「システム」の引数として「のconstのchar *」がかかりますが、あなたはそれのstd ::文字列を与えた:あなたはそれをこのようなchar*を与える必要があります。お試しください

system(dl.c_str()); 
2

systemconst char *の引数を必要とするので、dl.c_str()を呼び出してchar *std::stringのデータにする必要があります。

system(dl.c_str()); 
1

system() C++のタイプについて何も知りません。

system(dl.c_str());