• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 5 páginas
Resumen

Summary C++ Basic Input-Output

Document preview thumbnail
Vista previa 2 fuera de 5 páginas

The document provides an overview of basic input-output in C++, essential for interactive programming. It covers standard input (cin) and output (cout) streams, along with common operations like reading from the keyboard and displaying text on the screen. Detailed explanations of formatted and unformatted I/O are included, with practical examples demonstrating their usage. The notes also discuss error handling and stream manipulation, highlighting best practices to ensure efficient and user-friendly input-output operations in C++.

Vista previa del contenido

ELITE TUTORING




C++ Basic Input/Output
In this topic, we will learn to use the cin object to take input from the user, and
the cout object to display output to the user with the help of examples.

C++ Output
In C++, cout sends formatted output to standard output devices, such as the
screen. We use the cout object along with the << operator for displaying output.




Example 1: String Output
#include <iostream>
using namespace std;

int main() {
// prints the string enclosed in double quotes
cout << "This is C++ Programming";
return 0;
}

Output

This is C++ Programming


How does this program work?
• We first include the iostream header file that allows us to display output.
• The cout object is defined inside the std namespace. To use
the std namespace, we used the using namespace std; statement.
• Every C++ program starts with the main() function. The code execution
begins from the start of the main() function.

, ELITE TUTORING



• cout is an object that prints the string inside quotation marks " ". It is
followed by the << operator.
• return 0; is the "exit status" of the main() function. The program ends with
this statement, however, this statement is not mandatory.
Note: If we don't include the using namespace std; statement, we need to
use std::cout instead of cout .

This is the preferred method as using the std namespace can create potential
problems.
However, we have used the std namespace in order to make the codes more
readable.
#include <iostream>

int main() {
// prints the string enclosed in double quotes
std::cout << "This is C++ Programming";
return 0;
}




Example 2: Numbers and Characters Output

To print the numbers and character variables, we use the same cout object but
without using quotation marks.
#include <iostream>
using namespace std;

int main() {
int num1 = 70;
double num2 = 256.783;
char ch = 'A';

cout << num1 << endl; // print integer

Información del documento

Subido en
25 de julio de 2024
Número de páginas
5
Escrito en
2023/2024
Tipo
Resumen
$5.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
1
Artículos
69
Última venta
-




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes