FANDOM


16px-Pencil

Standard input is the stream where input for a computer program is held. The input is often then stored in a variable.

C Edit

#include <stdio.h>
 
#define MAX_LEN 20
 
char myString[MAX_LEN + 1];
fgets(myString, MAX_LEN + 1, stdin);

C++ Edit

#include <iostream>
#include <string>

int main()
{
  std::string myString;
  std::getline(std::cin, myString);

  std::cin >> myString;
  
  std::cin.get(myString);

  return 0;
}

C# Edit

string MyString = "";
MyString = Console.ReadLine();
Console.WriteLine(MyString);

VB.NET Edit

Dim MyString As String = ""
MyString = Console.ReadLine()
Console.WriteLine(MyString)

Haskell Edit

do myString <- getLine
   -- do stuff here

Java Edit

Old version using BufferedReader Edit

import java.io.*;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String myString = br.readLine();


Newer version using Scanner Edit

import java.util.Scanner;
Scanner scan = new Scanner(System.in);
String operat = scan.next(); //Change "String" to correct type.

Here used with int:

import java.util.Scanner;
Scanner scan = new Scanner(System.in);
int operat = scan.nextInt(); //Notice how "scan.next();" changed to "scan.nextInt();"

OCaml Edit

let my_string = read_line () in
  (* do stuff here *)

Perl Edit

my $myString = <STDIN>;

PHP Edit

$myString = fgets(STDIN);

Or:

$stdin = fopen('php://stdin', 'r'); // opens standard input
$line = fgets($stdin); // reads until user presses ENTER

Python Edit

2.x

myString = raw_input()

3.x

myString = input()

Ruby Edit

myString = gets
STDIN.gets

External Links Edit

See Also Edit

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.