Logo

Programming-Idioms

  • Pascal
  • C++
  • Go

Idiom #120 Read integer from stdin

Read an integer value from the standard input into the variable n

import "fmt"
_, err := fmt.Scanf("%d", &n)
import "fmt"
_, err := fmt.Scan(&n)

Warning: if the input has a leading 0, it will be interpreted as octal!
read(n);
#include <iostream>
std::cin >> n;
#include <stdio.h>
int n;
scanf("%d", &n);

New implementation...
< >
programming-idioms.org