Computer Science

cin C

Cin C is a C++ function that is used to read input from the user. It is commonly used in console-based applications to prompt the user for input and store the input in a variable. The function can read different types of data, such as integers, floating-point numbers, and characters.

Written by Perlego with AI-assistance

3 Key excerpts on "cin C"

  • Book cover image for: C++ Programming
    eBook - PDF

    C++ Programming

    From Problem Analysis to Program Design

    Recall that the standard input device is usually the keyboard, and the standard output device is usually the screen. To receive data from the keyboard and send output to the screen, every C11 program must use the header file iostream. This header file con- tains, among other things, the definitions of two data types, istream (input stream) and ostream (output stream). The header file also contains two variable declarations, one for cin (pronounced ‘‘see-in’’), which stands for common input, and one for cout (pronounced ‘‘see-out’’), which stands for common output. These variable declarations are similar to the following C11 statements: istream cin; ostream cout; To use cin and cout, every C++ program must use the preprocessor directive: #include Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. I/O Streams and Standard I/O Devices | 125 3 Variables of type istream are called input stream variables; variables of type ostream are called output stream variables. A stream variable is either an input stream variable or an output stream variable. Because cin and cout are already defined and have specific meanings, to avoid con- fusion, you should never redefine them in programs. The variable cin has access to operators and functions that can be used to extract data from the standard input device. You have briefly used the extraction operator >> to input data from the standard input device. The next section describes in detail how the extraction operator >> works.
  • Book cover image for: C++ Programming
    eBook - PDF

    C++ Programming

    Program Design Including Data Structures

    I/O Streams and Standard I/O Devices A program performs three basic operations: It gets data, it manipulates the data, and it outputs the results. In Chapter 2, you learned how to manipulate numeric data using arithmetic operations. In later chapters, you will learn how to manipu-late nonnumeric data. Because writing programs for I/O is quite complex, C 11 offers extensive support for I/O operations by providing substantial prewritten I/O operations, some of which you encountered in Chapter 2. In this chapter, you will learn about various I/O operations that can greatly enhance the flexibility of your programs. In C 11 , I/O is a sequence of bytes, called a stream, from the source to the desti-nation. The bytes are usually characters, unless the program requires other types of information, such as a graphic image or digital speech. Therefore, a stream is a sequence of characters from the source to the destination. There are two types of streams: Input stream: A sequence of characters from an input device to the computer. Output stream: A sequence of characters from the computer to an output device. Recall that the standard input device is usually the keyboard, and the standard output device is usually the screen. To receive data from the keyboard and send output to the screen, every C 11 program must use the header file iostream . This header file con-tains, among other things, the definitions of two data types, istream (input stream) and ostream (output stream). The header file also contains two variable declarations, one for cin (pronounced ‘‘see-in’’), which stands for common input , and one for cout (pronounced ‘‘see-out’’), which stands for common output . These variable declarations are similar to the following C 11 statements: istream cin; ostream cout; To use cin and cout , every C++ program must use the preprocessor directive: #include Copyright 2018 Cengage Learning.
  • Book cover image for: Learn C Programming
    eBook - ePub

    Learn C Programming

    A beginner's guide to learning C programming the easy and disciplined way

    We will then use the technique of experimentation, or more specifically, trial and observation, to discover and verify our understanding of how C input streams operate. We will later expand the concept of streams to include filesand file processing in Chapter 22, Working with Files, and Chapter 23, Using File Input and File Output. As we explore formatted console input, we will also look at a few important side examples to learn about using unformatted input and output, converting unformatted strings into integers or floats, and finally, creating internal strings from values and reading values from an internal string. The following topics will be covered in this chapter: Understanding input and output streams Revisiting formatted console output with printf() Exploring formatted console input with scanf() Using scanf() to read numerical values from the console Using scanf() to read string and character values from the console Controlling the scanf() input field width Exploring internal data conversion Using sscanf() and sprintf() to convert values into and from strings Exploring unformatted input and output Getting string input and output from the console usinggets()andputs() Converting strings into numbers withatoi()andatof() Creating a sorted list of names withgets()andputs() Technical requirements Continue to use the tools you chose in the Technical requirements section of Chapter 1, Running Hello,. World!. The source code for this chapter can be found at https://github.com/PacktPublishing/Learn-C-Programming. Introducing streams In the simplest terms, a stream is a sequence of bytes transferred in one direction from its source to its target. We have already discussed the abstract concept of an execution stream, or the flow of compiled CPU instructions from memory to the CPU. An execution stream is created when we successfully compile our source code files into an executable file
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.