C++ Standard Library C++ STL Library

C++ <cstdio> - stdin



The C++ <cstdio> stdin is a predefined stream. It is associated with the standard input stream, which is the default source of data for applications. In most systems, it is usually directed by default to the keyboard. At program startup, the stream is fully buffered if and only if the stream can be determined not to refer to an interactive device.

stdin is expanded to expressions of type FILE*. Therefore, it can be used with any function which expects an input stream (FILE*) as one of its parameters, like fgets() or fscanf().

In the <cstdio> header file, it is defined as follows:

#define stdin /* implementation-defined */

Example:

In the example below, stdin is used with fgets() function to take input from the keyword. It takes three inputs and finally print the content on the screen.

#include <cstdio>

int main() {
  char mystring [100];

  for(int i = 1; i<=3; i++) {
    fgets (mystring , 100 , stdin);
    printf("Name%d: %s", i, mystring);       
  }

  return 0;
}

If the following inputs are entered:

Ram
John
Sam

The output will be:

Name1: Ram
Name2: John
Name3: Sam

❮ C++ <cstdio> Library

5