Note details

Basic Input and Output in C++

BY c2lvr
August 23, 2025
Public
Private
253 views

Lecture: Basic Input and Output

Introduction

  • Welcome to Nesso Academy: Continuation from the previous lecture on the basics of IO stream.
  • Objective: Understand what input and output are, and how to perform input and output operations.

Lecture Topics

  1. std::cout
  2. std::endl
  3. std::cin

1. std::cout

  • Definition: std::cout is short for standard character output.
    • STDC: Standard
    • C: Character
    • Out: Output
  • Functionality: Used to display data as a sequence of characters on the console window.
  • Example:
    #include <iostream>
    
    int main() {
        std::cout << 42;
    }
    
    • Displays "42" as characters on the console.
    • Uses the insertion operator (<<) to output values.

2. std::endl

  • Purpose: Specifies a new line in the output.
  • Usage: Use std::endl at the end of a std::cout statement to signal a newline.
  • Example:
    std::cout << "Hello" << std::endl << "I am a teacher.";
    
    • Outputs:
      Hello
      I am a teacher.
      
  • Mechanism: Separates lines in the output to match expected formatting.

3. std::cin

  • Definition: std::cin stands for standard character input.
    • STDC: Standard
    • C: Character
    • In: Input
  • Functionality: Used to read input from the keyboard.
  • Example:
    #include <iostream>
    
    int main() {
        int age;
        std::cin >> age;
        std::cout << "You entered: " << age << std::endl;
    }
    
    • Reads an integer value from the user input and displays it back.
  • Multi-input Capability: Can chain extraction operators to read multiple values.
    std::cin >> age >> gender;
    
    • Receives more than one input.

Summary

  • Covered three main topics pertinent to input and output in C++.
  • Learned how to output using std::cout, manage new lines with std::endl, and take input with std::cin.
  • The importance of correctly using these components in creating effective console applications was demonstrated.

End of lecture. Thank you for watching. See you in the next one!

    Basic Input and Output in C++