JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

C++ : I/O COMMAND , The Standard Output Stream (cout) , Input Stream (cin) , Error Stream (cerr) ,Log Stream (clog)

Input Stream (cin) , Error Stream (cerr) ,Log Stream (clog) , C++ : I/O COMMAND , The Standard Output Stream (cout) :-
c++ statndard  input / output opertaion के लिए कई सारे कमांड्स को introduce किया है | अब इस article मे in सभी कमांड्स को discuss करेगे |
c++ I/O stream मे execute होता है जो की bytes के sequence के साथ execute होता है जब bytes a device like a keyboard, a disk drive, or a network connection etc. से  main memory की और transfer होता है तब इसे input operation कहते है | जब stream main memory से a device like a display screen, a printer, a disk drive, or a network connection, etc. की तरह मूव होता है तब इसे आउटपुट operation कहते है |
I/O Library Header Files
c++ प्रोग्राम मे निन्म header files होता है :-
1.<iostream>
इस file मे  cin, cout, cerr and clog objects है इन objects को निन्म condition के लिए use किया जाता है :
cin : इस operation का use standard input stream के लिए किया जाता है |
cout: इस operation का use standard output stream के लिए किया जाता है |
cerr : इस operation का use un-buffered standard error stream के लिए किया जाता है |
clog : इस operation का use buffered standard error stream के लिए किया जाता है |
2.<iomanip>
इस file का use formatted I/O operation जिसे parameter stream manipulators (setw या setprecision)के लिए किया जाता है |
3.<fstream>
इस file का use user-controlled file processing के लिए किया जाता है | इस प्रोसेस / file को file heading के article मे discuss करेगे | basic इस file मे input और आउटपुट operations को perform किया जाता है |
The Standard Output Stream (cout)
ostream class का object cout है | cout operation को connected to भी कहते है जिसे standard output device से display screen के बीच stream को pass किया जाता है |cout को stream insertion operator के साथ use किया जाता है | इसका syntax << होता है |
उदाहरन :
#include <iostream>
using namespace std;
int main() {
char str[] = “Hello ! Welcome “;
cout << “Value of str is : ” << str << endl;
}
जब इस प्रोग्राम को execute किया जाता है तब इसका आउटपुट होता है : −
Value of str is : Hello ! Welcome
c++ complier variable के type को define करने इसे stream insertion मे tranfer किया जाता है जहा पर इसे display किया जाता है | इस function << operator को output data items से overload किया जा सकता है |
किसी एक statement मे दो या दो से अधिक << को use किया जा सकता है |endl का use new line command के लिए किया जाता है |
The Standard Input Stream (cin)
istream class का object cin है | cin  operation standard input device, keyboard या mouse से  connect होता  है जिसे statandard input  device से display screen के बीच stream को pass किया जाता है |cin  को stream extraction operator के साथ use किया जाता है | इसका syntax >> होता है |
Source Code
#include <iostream>
using namespace std;
int main() {
char name[50];
cout << “Please enter name: “;
cin >> name;
cout << “Your name is: ” << name << endl;
}
जब उदाहरन को execute किया जाता है तब इसमें यूजर द्वारा name को input किया जाता है और इसे display किया जाता है | इसका आउटपुट होगा :-
Please enter name: Parth
Your name is: Parth
c++ complier variable के type को define करने इसे stream insertion मे tranfer किया जाता है जिसमे data को assign किया जाता है | नीचे दिए उदाहरनो मे ,
integer value को age मे assign किया जाता है |
cin>>age ;
अगर यूजर द्वारा multiple value को input कराया जाता तब cin statement निन्म होता है :
cin >> name >> age;
इस statement को निन्म तरह से लिख सकते है :-
cin >> name;
cin >> age;
The Standard Error Stream (cerr)
istream class का object cerr है | cerr  operation का use standard error device से releated error message को display करने के लिए किया जाता है  |object  cerr उन-defined buffered है अतः इस stream मे pass सभी data display screen पर तुरंत display हो जाता है |
उदाहरन :
#include <iostream>
using namespace std;
int main() {
char str[] = “Unable to read….”;
cerr << “Error message : ” << str << endl;
}
जब इस function को execute किया जाता है तब इसका आउटपुट होगा :-
Error message : Unable to read….
The Standard Log Stream (clog)
istream class का object clog है | clog operation का use standard error device से releated error message को display करने के लिए किया जाता है  |object  cerr defined buffered है अतः इस stream मे pass सभी data display screen पर तुरंत display हो जाता है | इस command से buffer मे error message तब तक सेव रहता है जब तक buffer full नहीं हो जाता है या इसे flush नहीं किया जा सकता है |
इसका उदाहरन निन्म है :
#include <iostream>
using namespace std;
int main() {
char str[] = “Unable to read….”;
clog << “Error message : ” << str << endl;
}
जब उदाहरन को execute किया जाता है तब इसमें यूजर द्वारा name को input किया जाता है और इसे display किया जाता है | इसका आउटपुट होगा :-
Error message : Unable to read….
इन छोटे उदाहरनो से इन सभी commands cout, cerr and clog मे differnce को समजना थोडा मुश्किल है | लेकिन जब प्रोग्राम की length काफी बड़ी होती है तब इन commands मे difference को अच्छी तरह से देखसकते है |
Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now