LoginSignup
1
0

More than 5 years have passed since last update.

CとC++の標準入力

Posted at

Cの標準入力

#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    printf("Input : %d\n", n);
    return 0;
}
  • scanfの第二引数は、変数のアドレスを渡す必要がある

C++の標準入力

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    cout << "Input : " << n << endl;
    return 0;
}
  • iostreamというライブラリが使える
  • ただiostreamを使った書き方は遅いらしく、競プロガチ勢は scanf などを使う模様
  • C++なので当然Cと全く同じ書き方もできる
1
0
1

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