C++ iostream Library (C++ iostream लाइब्रेरी)


The <iostream> header is one of the most important headers in C++. It provides facilities for input and output operations using streams. These facilities allow programs to communicate with the keyboard, monitor, and other input/output sources.

<iostream> हेडर C++ के सबसे महत्वपूर्ण हेडर्स में से एक है। यह Streams के माध्यम से इनपुट और आउटपुट संचालन की सुविधा प्रदान करता है। इसकी सहायता से प्रोग्राम कीबोर्ड, मॉनिटर तथा अन्य इनपुट/आउटपुट स्रोतों के साथ डेटा का आदान-प्रदान कर सकते हैं।

What Is the iostream Library? (iostream लाइब्रेरी क्या है?)

The <iostream> header provides standard stream objects such as cin, cout, cerr, and clog. These objects are used to read input, display output, and report errors or diagnostic messages.

<iostream> हेडर cin, cout, cerr तथा clog जैसे Standard Stream Objects उपलब्ध कराता है। इनका उपयोग इनपुट लेने, आउटपुट प्रदर्शित करने तथा त्रुटि या अन्य जानकारी से संबंधित संदेश दिखाने के लिए किया जाता है।

A stream is a flow of data between a program and an input/output source or destination.

स्ट्रीम (Stream) डेटा का वह प्रवाह है जिसके माध्यम से प्रोग्राम और किसी इनपुट/आउटपुट स्रोत या गंतव्य के बीच डेटा का आदान-प्रदान होता है।

Important Objects of iostream (iostream के महत्वपूर्ण ऑब्जेक्ट्स)

ObjectPurpose (उपयोग)
cinReads standard input, usually from the keyboard. सामान्यतः कीबोर्ड से इनपुट लेता है।
coutDisplays standard output, usually on the monitor. सामान्यतः मॉनिटर पर आउटपुट दिखाता है।
cerrReports errors immediately; it is typically unbuffered. त्रुटि संदेश प्रदर्शित करता है; सामान्यतः यह अनबफर्ड होता है।
clogDisplays diagnostic or log messages; it is typically buffered. लॉग या जानकारी संबंधी संदेश प्रदर्शित करता है; सामान्यतः यह बफर्ड होता है।

Example: Using cin and cout

The following program demonstrates how to accept data from the user and display it using cin and cout.

निम्नलिखित प्रोग्राम cin और cout की सहायता से उपयोगकर्ता से डेटा लेने तथा उसे प्रदर्शित करने का तरीका बताता है।

#include <iostream>
using namespace std;

int main()
{
    int age;

    cout << "Enter your age: ";
    cin >> age;

    cout << "Your age is " << age << endl;

    return 0;
}

Sample Output

Enter your age: 20
Your age is 20

Explanation (व्याख्या):

  • #include <iostream> makes the required stream declarations available.

  • cin >> age reads a value into the variable age.

  • cout << ... displays the message and the entered value.

  • endl inserts a newline and flushes the output stream.

  • #include <iostream> आवश्यक स्ट्रीम घोषणाओं को उपलब्ध कराता है।

  • cin >> age इनपुट मान को age वेरिएबल में स्टोर करता है।

  • cout << ... संदेश और दर्ज किया गया मान प्रदर्शित करता है।

  • endl नई लाइन जोड़ता है और आउटपुट स्ट्रीम को फ्लश करता है।

Important C++ Stream Headers (C++ की महत्वपूर्ण स्ट्रीम हेडर फाइलें)

The C++ standard library provides several related headers for different input/output tasks.

C++ Standard Library में इनपुट/आउटपुट से संबंधित अलग-अलग कार्यों के लिए कई हेडर फाइलें उपलब्ध हैं।

1. <iostream>

This header provides the standard stream objects cin, cout, cerr, and clog, along with the declarations needed for standard stream operations.

यह हेडर cin, cout, cerr और clog जैसे Standard Stream Objects तथा सामान्य स्ट्रीम संचालन के लिए आवश्यक घोषणाएँ प्रदान करता है।

2. <ios>, <istream>, <ostream> and <streambuf>

These headers provide important components of the C++ stream system. They define stream state and formatting facilities, input-stream operations, output-stream operations, and stream-buffer functionality.

ये हेडर्स C++ Stream System के महत्वपूर्ण घटक प्रदान करते हैं। इनमें Stream State और Formatting, Input Stream Operations, Output Stream Operations तथा Stream Buffer से संबंधित सुविधाएँ शामिल हैं।

3. <fstream>

The <fstream> header provides classes for file handling through streams.

<fstream> हेडर स्ट्रीम के माध्यम से फाइलों पर कार्य करने के लिए क्लासें प्रदान करता है।

  • ifstream – Reads data from a file. फाइल से डेटा पढ़ता है।

  • ofstream – Writes data to a file. फाइल में डेटा लिखता है।

  • fstream – Supports both input and output operations on files. फाइल पर पढ़ने और लिखने दोनों कार्यों का समर्थन करता है।

4. <sstream>

The <sstream> header provides stream operations on strings. It is useful when extracting values from strings or building strings using stream-style operations.

<sstream> हेडर स्ट्रिंग पर Stream Operations की सुविधा प्रदान करता है। इसका उपयोग स्ट्रिंग से मान निकालने या स्ट्रीम की सहायता से स्ट्रिंग बनाने में किया जाता है।

Important classes include:

  • stringstream – Supports input and output operations on a string stream.

  • istringstream – Reads data from a string.

  • ostringstream – Builds a string through output operations.

प्रमुख क्लासें:

  • stringstream – स्ट्रिंग स्ट्रीम पर इनपुट और आउटपुट दोनों कार्य करता है।

  • istringstream – स्ट्रिंग से डेटा पढ़ता है।

  • ostringstream – आउटपुट संचालन द्वारा स्ट्रिंग तैयार करता है।

5. <iomanip>

The <iomanip> header provides manipulators that help format input and output. They are useful for setting field width, fill characters, precision, and alignment.

<iomanip> हेडर इनपुट और आउटपुट की फॉर्मेटिंग के लिए Manipulators प्रदान करता है। इनकी सहायता से फील्ड विड्थ, फिल कैरेक्टर, प्रिसिजन तथा अलाइनमेंट निर्धारित किया जा सकता है।

Some commonly used manipulators are:

  • setw() – Sets the minimum field width. न्यूनतम फील्ड विड्थ निर्धारित करता है।

  • setfill() – Sets the fill character. खाली स्थान भरने वाला कैरेक्टर निर्धारित करता है।

  • setprecision() – Controls floating-point precision. फ्लोटिंग-पॉइंट प्रिसिजन नियंत्रित करता है।

  • fixed – Displays floating-point values in fixed-point notation. फ्लोटिंग-पॉइंट मान को Fixed-Point Format में प्रदर्शित करता है।

  • left – Left-aligns output. आउटपुट को बाईं ओर संरेखित करता है।

  • right – Right-aligns output. आउटपुट को दाईं ओर संरेखित करता है।

Note: endl is provided through <iostream>; it is not a manipulator from <iomanip>.

ध्यान दें: endl, <iostream> के माध्यम से उपलब्ध होता है; यह <iomanip> का मैनिपुलेटर नहीं है।

Conclusion (निष्कर्ष)

The <iostream> header is fundamental to input and output operations in C++. Its stream objects allow programs to accept user input, display results, and report errors. Related headers such as <fstream>, <sstream>, and <iomanip> extend these capabilities to file handling, string processing, and output formatting.

C++ में इनपुट और आउटपुट संचालन के लिए <iostream> हेडर अत्यंत महत्वपूर्ण है। इसके Stream Objects की सहायता से प्रोग्राम उपयोगकर्ता से इनपुट ले सकते हैं, परिणाम प्रदर्शित कर सकते हैं तथा त्रुटि संदेश दिखा सकते हैं। इसके अतिरिक्त, <fstream>, <sstream> और <iomanip> जैसे संबंधित हेडर्स फाइल हैंडलिंग, स्ट्रिंग प्रोसेसिंग और आउटपुट फॉर्मेटिंग की सुविधाएँ प्रदान करते हैं।

Comments

  1. This is a very informative and useful blog. I really enjoyed reading the content because it is simple, clear, and easy to understand. The information shared in this article is helpful for readers who want to learn more about the topic. I especially liked how the points were explained with practical details and useful suggestions. Such well-written blogs make it easier to discover new ideas and gain valuable knowledge. Thank you for sharing this helpful information. I look forward to reading more interesting and informative articles like this in the future. Keep up the great work and continue sharing valuable content.
    Best Fashion Designing institute in Delhi NCR
    Best Makeup Training Institute in Delhi NCR.
    best computer institute in delhi NCR
    Typing & Shorthand Institute in Delhi NCR

    ReplyDelete

Post a Comment

Popular posts from this blog

Important Questions of C++ including OOP's

Programming Methodologies and OOP's using C++ Language

OOP's using CPP Syllabus AND Programming Methodologies and Data Structures Using C++ (NEP 2020)