LoginSignup
0
0

More than 3 years have passed since last update.

Cygwinでc++ファイルをコマンドライン引数を指定して実行する

Last updated at Posted at 2019-07-08

実行環境

実行にはwindows10でcygwin64 terminalを使っています。

やってみる

今回は~/lesson11/src内のtrain.cppファイルを例に実行します。
train.cppファイルの中身は以下のようになっています。このプログラムはプログラム名と仮引数を表示するというものです。
image.png
メイン関数の引数であるargcとargvはそれぞれargument_countとargument_vectorの略です。
・argc
メイン関数にプログラム名と仮引数と合わせた個数を渡します。
・argv
char*へのポインタで配列の最初の文字列であるargv[0]を指します。


まず、実行したいファイルがある場所に移動します。
image.png

g++ [ファイル名]と打ち込んでコンパイルします。
image.png
すると、ディレクトリ内にa.exeというファイルが生成されます。
image.png
コンパイルされたファイルは./a.exeと叩くと実行できますが、今回はコマンドライン引数を指定するので./a.exeの後に引数を加えて実行します。
image.png
表示することができました。

参考文献

-新明解 c++入門

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0