From 593c230585acd5504ceeb244d825db17afcf0526 Mon Sep 17 00:00:00 2001 From: Ritesh Date: Sat, 1 Jun 2024 18:40:53 +0530 Subject: [PATCH] Update input-output-in-cpp.md (#104) --- docs/day-04/input-output-in-cpp.md | 63 ++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/docs/day-04/input-output-in-cpp.md b/docs/day-04/input-output-in-cpp.md index 549602e0b..9c2ff5238 100644 --- a/docs/day-04/input-output-in-cpp.md +++ b/docs/day-04/input-output-in-cpp.md @@ -6,13 +6,62 @@ sidebar_label: "Input and Output" slug: input-output-in-cpp --- -TASK: +## What is Input and Output in C++? + +Input and Output (I/O) in C++ refer to the process of communicating with the user or other parts of the program. Input typically involves receiving data from an external source, such as the user via keyboard, or from a file. Output involves displaying information to the user, writing data to files, or sending data to other devices. + + -1. What is Input and Output in C++? -2. Why do we use Input and Output in C++? -3. How to take input from the user in C++? -4. How to display output to the user in C++? -5. Take Multiple Inputs from the User in C++. IMAGE FILE: -![Input Output in CPP](../../static/img/day-04/input-output-in-cpp.png) \ No newline at end of file +![Input Output in CPP](../../static/img/day-04/input-output-in-cpp.png) + + +## Why do we use Input and Output in C++? + +Input and Output are essential for creating interactive programs. They allow users to provide input to the program, which can then process the data and produce output, making the program more useful and versatile. + +## How to take input from the user in C++? + +In C++, you can take input from the user using the `std::cin` object, which is part of the `` library. Here's an example: + +```cpp +#include + +int main() { + int num; + std::cout << "Enter a number: "; + std::cin >> num; + std::cout << "You entered: " << num << std::endl; + return 0; +} +``` + +## How to display output to the user in C++? + +To display output to the user in C++, you can use the `std::cout` object, also part of the `` library. Here's an example: + +```cpp +#include + +int main() { + std::cout << "Hello, world!" << std::endl; + return 0; +} +``` + +## Take Multiple Inputs from the User in C++ + +To take multiple inputs from the user in C++, you can simply use multiple `std::cin` statements. Here's an example: + +```cpp +#include + +int main() { + int num1, num2; + std::cout << "Enter two numbers: "; + std::cin >> num1 >> num2; + std::cout << "Sum: " << num1 + num2 << std::endl; + return 0; +} +```