1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【C++】基礎を学ぶ⑦~cinで入力を受け取る~

Last updated at Posted at 2022-07-09

cinで入力を受け取る

cin >> 変数でキーボードからの入力を受け取ることができます

cinの使い方

変数を宣言する
cin >> 変数で変数に値を代入する

#include <iostream>

using namespace std;

int main(){
  int x;
  cin >> x;
  cout << "入力した値:" << x << endl;
  return 0;
}

入力

1

出力

入力した値:1

複数の値を受け取る

#include <iostream>

using namespace std;

int main(){
  string x;
  int y;
  cin >> x;
  cin >> y;
  cout << x << y << endl;
  return 0;
}

スペース区切りで入力する

入力

Hello, 1

出力

Hello,1

改行区切りでも入力できる

入力

Hello,
1

出力

Hello,1

次の記事

【C++】基礎を学ぶ⑧~if文~

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?