C Plus Plus cin

From GMpedia.org Wiki

Jump to: navigation, search
The CIN command as shown in a C++ Command Console Window.
The CIN command as shown in a C++ Command Console Window.
cin is a C++ command that allows the user to input data. It could be used after using the #include command to include iostream, which initializes the input and output.

"cin" stands for C Input, meaning it inputs text.

[edit] Syntax

int variable;
std::cin >> variable;

The statement can be interpreted as follows: cin is an object, defined in the iostream header. The extraction operator >> means the same as: take a stream of data from cin and put it into the variable variable. Since many cin command may be used, using "std::" may be tiring, so the using statement might be handy.

The command allows the user to enter text. When the user presses Enter, a newline character '\n' is added.

[edit] The object cin

cin is in fact an object, as mentioned earlier. An object has methods and properties.

A few methods of cin that are often used:

  • get(): gets the next character from the input buffer. This statement can also be used to prevent the window from being closed when the program has finished.
  • getline(): gets the next line of text from the input buffer.

[edit] See Also

Personal tools