This language bar is your friend. Select your favorite languages!

Idiom #120 Read integer from stdin

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

import "fmt"
_, err := fmt.Scanf("%d", &n)
import "fmt"
_, err := fmt.Scan(&n)
#include <stdio.h>
#include <stdlib.h>
char inbuff[1000];

int main(int, char **) {
   int n;
   if (!fgets(inbuff, sizeof(inbuff), stdin))
      fabort("Can't read from input");
   n = atoi(inbuff);
   printf("You entered %d\n", n);
#include <iostream>
std::cin >> n;
import std.stdio;
readf("%d", &n);
n = String.to_integer IO.gets ""
n <- (read :: String -> Int) <$> getContents
import java.util.Scanner;
Scanner in = new Scanner(;
n = in.nextInt();
n ="n")
fscanf(STDIN, "%d\n", $n);
my $n = <> + 0;  # read a line from STDIN, add 0 to convert to int
input_var = int(raw_input("Input Prompting String: "))
n = gets.to_i
fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");

let x = get_input().trim().parse::<i64>().unwrap();

Do you know the best way to do this in your language ?
New implementation...

Idiom created by