முக்கிய உள்ளடக்கத்திற்குச் செல்லவும்
eLearner.app
தொகுதி 1 · பாடம் 3 இன் 3பாடத்திட்டத்தில் 3/18~10 min
தொகுதி பாடங்கள் (3/3)

உள்ளீடு/வெளியீடு மற்றும் ஸ்ட்ரீம்கள்

In C++, standard input and output are managed via streams (data flows) defined in the <iostream> standard library.

The two main objects you will use are:

  • std::cout: the output stream (associated with the screen).
  • std::cin: the input stream (associated with the keyboard).

Printing with std::cout

To send data to the screen, we use the insertion operator <<:

Code
#include <iostream>

int main() {
    std::cout << "Hello!" << " Welcome to C++." << std::endl;
    return 0;
}
  • << can be chained to print different texts and variables consecutively.
  • std::endl inserts a newline character (\n) and flushes the stream (ensures that the output is immediately displayed on the screen).

Reading with std::cin

To read values entered by the user, we use the standard input stream std::cin combined with the extraction operator >>:

Code
#include <iostream>

int main() {
    int age;
    std::cout << "Enter your age: ";
    std::cin >> age; // Extracts user input and saves it into age
    std::cout << "You are " << age << " years old." << std::endl;
    return 0;
}

Try it yourself

உடற்பயிற்சி#cpp.m1.l3.e1
முயற்சிகள்: 0ஏற்றுகிறது…

Print the message 'C++ is fast!' followed by a newline using std::endl.

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

Usa l'operatore d'inserimento `<<`con`std::cout`e`std::endl`.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்

உடற்பயிற்சி#cpp.m1.l3.e2
முயற்சிகள்: 0ஏற்றுகிறது…

Declare an integer variable named number. Read its value from standard input using std::cin and then print it using std::cout.

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

To read use `std::cin >> number;`and to print use`std::cout << number;`.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்