LoginSignup
9
9

More than 5 years have passed since last update.

C++ 環境構築とHello World

Last updated at Posted at 2014-08-19

環境構築

Mac OSX

デフォルトで環境がインストールされているので、確認する。

$ which g++
/usr/bin/g++

Windows

Eclipseや、Visual StudioなどのIDEを利用する。

CentOS

インストールコマンド

$ sudo yum install gcc-c++

Debian

インストールコマンド

$ sudo apt-get install g++

Hello World

main.cpp
#include <iostream>

int main()
{
  std::cout<<"hello world"<<std::endl;
  return 0;
}

コンパイルすると、デフォルトでは、ファイル名a.outで出力される。
実行するときは、同一ディレクトリでもフルパスで指定する。(パスを指定しないと、シェルがライブライリ内を検索するため)

$ g++ main.cpp

$ ./a.out

hello world


出力ファイル名を指定したい場合は、コンパイル時に、-o 出力ファイル名オプションをつける。

$ g++ -o jk main.cpp

9
9
2

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
9
9