Skip to content

Instantly share code, notes, and snippets.

@lablabkun
Last active June 15, 2017 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lablabkun/ec5a9bca376d2579f37955b8632d0eed to your computer and use it in GitHub Desktop.
Save lablabkun/ec5a9bca376d2579f37955b8632d0eed to your computer and use it in GitHub Desktop.
構造体の使用例
#include <iostream>
#include <string>
// robotという構造体を作成する
struct robot
{
std::string color; // ロボットの色
int button; // ロボットのボタンの数
int arm; // ロボットの腕の数
};
int main()
{
robot hitogata; // 人型ロボットについて
robot osouji; // お掃除ロボットについて
// 人型ロボットについての情報を入力
hitogata.color = "green"; // 人型ロボットの色
hitogata.button = 4; // 人型ロボットのボタンの数
hitogata.arm = 2; // 人型ロボットのボタンの数
// お掃除ロボットについての情報を入力
osouji.color = "gray"; // お掃除ロボットの色
osouji.button = 4; // お掃除ロボットのボタンの数
osouji.arm = 2; // お掃除ロボットの腕の数
std::cout << "人型ロボットのボタンの数は" << hitogata.button << "だよ" << std::endl;
std::cout << "お掃除ロボットの色は" << osouji.color << "だよ" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment