2016-04-01 1 views
0

2つのコマンドライン引数を解析して引数を出力するC++コードがあります。引数の1つはgoogle検索のURLです。私は以下のようにコンパイルした後、コマンドラインからURLを渡すとき、私はそこにされているように見えますコマンドラインでURLを渡す(C++)

[1] 8680 
[2] 8681 
[3] 8682 
[4] 8683 
[5] 8684 
[6] 8685 
[7] 8686 
[2] Done     ion=1 
[3] Done     espv=2 
[4] Done     ie=UTF-8 
[6]- Done     q=size%20of%20unsigned%20char%20array%20c%2B%2B 

、と私は出力を得る

./demo 1 https://www.google.co.in/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&client=ubuntu&q=size%20of%20unsigned%20char%20array%20c%2B%2B&oq=length%20of%20unsigned%20char*%20arra&aqs=chrome.4.69i57j0l5.13353j0j7 

int main(int argc, char* argv[]) 
{ 
    std::cout << argv[1] << argv[2] << "\n"; 

} 

以下のコードを貼り付け文字列のいくつかの内部分割。文字列全体を取得する方法はありますか?

ありがとうございます。

+0

デリミタ '&'で文字列を分割していると思います。 – rohitnambisan99

答えて

1

あなたはそれを引用する必要があります。それ以外の場合は、&がシェルによって「バックグラウンドで&の左側にあるものを呼び出す」と解釈されます。

私はあなたのプログラムをechoに置き換える特権を取った。

グッド:

悪い
$ echo "https://www.google.co.in/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&client=ubuntu&q=size%20of%20unsigned%20char%20array%20c%2B%2B&oq=length%20of%20unsigned%20char*%20arra&aqs=chrome.4.69i57j0l5.13353j0j7" 
https://www.google.co.in/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&client=ubuntu&q=size%20of%20unsigned%20char%20array%20c%2B%2B&oq=length%20of%20unsigned%20char*%20arra&aqs=chrome.4.69i57j0l5.13353j0j7 

あなたが内部の何を評価しようとするからあなたのシェルを停止するために、引数を引用すると、あなたは、単一引用符を使用する必要があり、 '必要
$ echo https://www.google.co.in/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&client=ubuntu&q=size%20of%20unsigned%20char%20array%20c%2B%2B&oq=length%20of%20unsigned%20char*%20arra&aqs=chrome.4.69i57j0l5.13353j0j7 
[1] 21705 
[2] 21706 
https://www.google.co.in/search?sourceid=chrome-psyapi2 
[3] 21707 
[4] 21708 
[5] 21709 
[6] 21710 
[7] 21711 
[1] Done     echo https://www.google.co.in/search?sourceid=chrome-psyapi2 
[2] Done     ion=1 
[3] Done     espv=2 
[4] Done     ie=UTF-8 
[5] Done     client=ubuntu 
[6]- Done     q=size%20of%20unsigned%20char%20array%20c%2B%2B 
[7]+ Done     oq=length%20of%20unsigned%20char*%20arra 
+0

あなたの素早い返信をありがとうございました。:)それは美しく機能しました! – rohitnambisan99

1

それ。

コマンドライン上のすべてのアンパサンド "&"がバックグラウンドプロセスを起動します。

最初のプロセスは./demo 1 https://www.google.co.in/search?sourceid=chrome-psyapi2であり、以下はすべて変数への割り当てです。あなたは、バックグラウンド・プロセス2がion=1(PID 8681)であることを出力(あなたはそれのすべてを掲示していないように見える)

[1] 8680 
[2] 8681 
[3] 8682 
[4] 8683 
[5] 8684 
[6] 8685 
[7] 8686 
[2] Done     ion=1 
[3] Done     espv=2 
[4] Done     ie=UTF-8 
[6]- Done     q=size%20of%20unsigned%20char%20array%20c%2B%2B 

から見ることができます

、工程3(PID 8682)は、espv=2です等々。

+0

@molbdniloありがとう...それはうまくいった。 :) – rohitnambisan99

関連する問題