C++ में Basic Input और Output की संपूर्ण जानकारी

C++ में Basic Input और Output  क्या है

Programming, में input और output (I/O) operations महत्त्वपूर्ण है क्योंकि ये Programs को Users के साथ Communicate करने में, External sources से Information प्राप्त करने मे और Result को प्रदर्शित करने में सक्षम बनाते है

C++, में ये Operations Stream द्वारा Manage किए जाते है जो एक Program के अंदर तथा बाहर Data के प्रवाह के लिए Channels के समान कार्य करता है 

कल्पना कीजिए कि Streams एक Pipelines के समान है जो Data को ले जाता है उदाहरण के लिए जब आप Keyboard का Use करके कुछ Input करते है या Screen पर एक Message Output करते है या दिखाते है तब आप इस Sreams का ही Use करते हैं  

C++ मे, Standard library I/O कार्यों को प्रभावी रूप से Handle करने के लिए Tools का एक शक्तिशाली Sets प्रदान करता है  

C++ में Input/Output के लिए Header files 

C++ में Input/Output के लिए निम्न
Header files उपलब्ध है
1) iostream
2) iomanip

iostream header file

C++ Programming में `<iostream>` header अत्यन्त महत्त्वपूर्ण file है यह programs को Users के साथ Communicate करने और Information को प्रदर्शित करने में मदद करता है
इसका पूरा नाम Input/Output Stream है

इसमें standard input (`std::cin`), standard output (`std::cout`), standard error (`std::cerr`) और अन्य विभिन्न stream manipulators शामिल है
उदाहरण के लिए `std::cin` का Use करके User से कोई भी Data Input के रूप में ले सकते हैं `std::cout` आपको Screen पर Messages print करने की अनुमति देता है और `std::cerr` Error को प्रदर्शित करने के लिए Use किया जाता है 

आमतौर पर सबसे अधिक Use होने वाला `<iostream>` के दो घटक `std::cin` और `std::cout` है जो क्रमशः User से Input और Console में Output दिखाने जैसे कार्यों को Handle करता है

Standard Input (`std::cin`)

'std::cin` का प्रयोग Users से Input read करने में होता है यह Programs को Runtime के दौरान User द्वारा Enter किए गए Data को accept करने की अनुमति देता है 
 
Example:
नीचे हम User से उनका Age Input करने के लिए Program में निम्न प्रकार से std::cin का का प्रयोग करेंगे।

Program to use Standard Input (`cin`)  
#include<iostream> 
using namespace std;
int main()
{
    int age;
    cout << "Enter your age: ";
    cin >> age;
    cout << "You age is: " << age << endl;
    return 0;
}
Output:
Enter your age: 30
You age is: 30

ऊपर Program में 'cin` का उपयोग, User द्वारा entered की गई Integer value को read करने और उसे 'age' नामक variable में Store करने के लिए करते है
  
Note:
C++ program में header files के बाद using namespace std; का Use करके standard library functions को बिना std:: लगाए Use कर सकते हैं

चुकि ऊपर के Program में हमने using namespace std; का Use किया है अतः हमे cin और cout के पहले std::cin और std::cout लगाने की जरूरत नहीं होगी इससे Coding का कार्य और सरल हो जाता है

Standard Output (`std::cout`):

`std::cout` का Use Console में Output प्रदर्शित करने के लिए किया जाता है यह Programs को Message, result, या अन्य सूचनाओं को User को प्रदर्शित करने मे सक्षम बनाता है 
Program to use Standard Output (`std::cout`)
 
#include <iostream>
using namespace std;
int main() 
{
cout << "Hello, world!" <<endl;
 return 0;
}
Output:
Hello, world!

Program to use standard output (`std::cout`) 
#include <iostream>
using namespace std;
int main() 
{
 
cout << "Hello, Students!" <<endl;
cout << "We are learning C++";
    return 0;
}
 Output:
Hello, Students!
We are learning C++  

Standard Input Stream (cerr)

C++ में cerr Input/Output (I/O) functionality के भाग है जो विशेषकर error message और error संबंधित Output जानकारियों को handle करने के लिए Design किये गए है

cout, से भिन्न जो सामान्य Output के लिए Use किया जाता है cerr, error messages को प्रदर्शित करने के लिए आरक्षित है

अतः cerr आपको एक Clear error message प्रदान करता है जिसकी सहायता से आप अपने प्रोग्राम में कोई भी Issue को पहचान और उसका समाधान कर सकते हैं।

Program to use standard output (`std::cout`)   
#include <iostream>
using namespace std;
int main()
 {
 cerr << "An error encountered: !" << endl;
    return 0;
}
Output: 
An error encountered: 

iomanip

C++ में, iomanip एक header file है इसका पूरा Input/Output manipulators है जो Input और Output को Manipulate और Formatting करने के लिए Tools प्रदान करता है

यह Input और Output के alignment, width, precision तथा अन्य Formatting features को Modify करने की अनुमति देते हैं

ये Manipulators, screen पर Data को कैसे Display करना है या कैसे User से Data read करना है, को control करने में मदद करते हैं यह Data को एक निश्चित तरीके से प्रस्तुत करने के लिए सहायक है।

Program to use iomanip 
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
 int formatNum = 768;
cout << setw(7) << setfill('*') << formatNum << endl; 
    return 0;
}
Output:
****768

 Related Posts

> C++ क्या है? उसके इतिहास, गुण, उपयोग, फायदे और नुकसान 

> Basic structure of C++ Program 

> C++ में Tokens क्या है? और उसके प्रकार

> C++ Variables क्या है?, उसके प्रकार, उसे कैसे Declare, Define करते हैं

> C++ में Constants क्या है? उसके प्रकारों की संपूर्ण जानकारी

> Data type in C++ की संपूर्ण जानकारी 

> C+ में Operators और उसके प्रकार जानें Practical सहित 

> C++ में Conditional और उसके प्रकारों को जानें Practical सहित 

> C++ में Looping statements और उसके प्रकार Practical सहित 

> C++ में Jump Statements और उसके प्रकारों की संपूर्ण जानकारी Practical सहित

> C++ में Array क्या है? और उसके प्रकारों की जानकारी Practical सहित

> C++ में Function क्या है उसके प्रकार, उपयोग प्रोग्राम सहित 

> C++ में Structure क्या है Practical सहित

> OOPs Concepts in C++ in Hindi- C++ में OOPs के बारे में

> Oops के फायदे और नुकसान की जानकारी 

> OOP और POP के बीच अंतर 

> C++ में Class और Object की सम्पूर्ण जनकारी

> C++ में Array of Objects क्या है? 

> C++ में Pointers, Pointer to an objects, Pointer to an Array की संपूर्ण जानकारी हिंदी में।

C++ में Passing objects क्या है

> C++ में Reference और Type Casting की संपूर्ण जानकारी

> C++ में Access specifier की संपूर्ण जानकारी 

> C++ में Static Data Members और Member Functions के बारे में Practical सहित 

> C++ में Memory allocation और Memory management operators (new और delete) Practical सहित 

> Friend Function in C++ in Hindi 

> Friend Class in C++ in Hindi Practical सहित 

> Inline function in C++ in Hindi 

> Function Overloading in C++ in Hindi Practical सहित 

> Operator Overloading in C++ in Hindi Practical सहित 

> C++ में Constructor क्या है और उसके प्रकारों की संपूर्ण जानकारी

> C++ में Destructor क्या है ?उसकी संपूर्ण जानकारी

> C++ मे Inheritance क्या है उसके प्रकारों को जानें प्रोग्राम सहित

> C++ में Polymorphism क्या है? और उसके प्रकारों को जानें

> C++ में Virtual function की संपूर्ण जानकारी

> C++ में File handling की संपूर्ण जानकारी 

> C++ में Exception handling  की संपूर्ण जानकारी