006.- Curso C++ Básico. Librería Estándar iostream.
Introduction to IOStream in C++
Overview of IOStream Library
- The video tutorial focuses on the IOStream library, the first standard library in C++, which facilitates input and output operations.
- To use this library, it must be included at the top of the code as a preprocessor directive, allowing access to its functionalities across all relevant files.
Key Features of IOStream
- The IOStream library contains predefined variables such as
STDOut, which is part of a namespace that helps the compiler locate output functions within standard libraries.
- The compiler searches for
Coutwithin the contents of IOStream when referenced in code.
Using Cout for Output
Printing to Console
Coutallows data to be printed to the console as text, utilizing character output functionality.
- It can also print values stored in variables; for example, initializing a variable and using
Coutwith an insertion operator displays its value.
Multiple Outputs on One Line
- The insertion operator enables printing multiple items on one line by chaining outputs together.
- An example demonstrates how to print both text and variable values simultaneously using
Cout.
Formatting Output
Managing Line Breaks
- When attempting to print information across multiple lines, separate statements do not automatically create new lines in console output.
- To achieve line breaks, programmers must explicitly indicate where they want new lines using specific commands or characters.
Using endl for New Lines
- The command
endl, part of the IOStream library, can be used alongsideCoutto insert a newline character into console output.
- While some programmers prefer using newline characters directly due to performance reasons, others may opt for
endlfor clarity and structure.
Input Handling with Cin
Introduction to Cin Variable
- Another predefined variable from the IOStream library is
Cin, which stands for character input and allows users to store keyboard inputs into variables.
Storing User Input
- For effective input handling, user input must first be stored in a variable before it can be displayed using
Cout.
Example Demonstration
Uso del operador de extracción en programación
Introducción al operador de extracción
- En la tercera declaración, se utiliza el operador de extracción para permitir que el usuario ingrese datos.
- Se asigna el valor ingresado por el usuario a la variable
x, que inicialmente estaba vacía.
Visualización del resultado
- Después de almacenar el valor en
x, se emplea nuevamente un comando para mostrar este valor almacenado.