C++ में Input and Output के लिए streams का इस्तेमाल किया जाता है |
सामान्य जीवन में भी दो मुख्य input and output devices है | एक Keyboard
है और दूसरा Desktop/Monitor | Keyboard से दिया हुआ input Monitor/Desktop
की screen पे Output के माध्यम से दिखता है |
C++ में ऐसे ही कुछ header files है और इन header files में input/Output होते है |for eg. cin और cout
Input/Output के लिए C++ में तीन Header Files है |
iomanip : iomanip ये भी एक input/output library का हिस्सा है | जिसमे arguments के साथ manipulator functions होते है | iomanip formatted input/Output के लिए इस्तेमाल किया जाता है |
fstream : fstream का इस्तेमाल files के लिए होता है | File को read और write करना हो तो इस header file को include करना जरुरी होता है |
C++ में ऐसे ही कुछ header files है और इन header files में input/Output होते है |for eg. cin और cout
Input/Output के लिए C++ में तीन Header Files है |
- iostream
- iomanip
- fstream
iomanip : iomanip ये भी एक input/output library का हिस्सा है | जिसमे arguments के साथ manipulator functions होते है | iomanip formatted input/Output के लिए इस्तेमाल किया जाता है |
fstream : fstream का इस्तेमाल files के लिए होता है | File को read और write करना हो तो इस header file को include करना जरुरी होता है |
cout(Console Output) : Standard Output Stream
- cout output screen पर दिखाता है |
- cout ये ostream class का object है |
- cout के साथ insertion operator(<<) का भी इस्तेमाल किया जाता है |
- insertion operator को एक ही line में variable के साथ अनेक insertion operators(<<) का इस्तेमाल किया जाता है |
- insertion operator 'output' के लिए इस्तेमाल किया जाता है |
- insertion operator के साथ endl का भी इस्तेमाल किया जाता है | ये line के आखिर में इस्तेमाल होता है |
#include <iostream.h>
using namespace std;
int main(){
cout<<"Hello World!"<<endl;
return 0;
}
Output:
Hello World!
cin(Console Input) : Standard Input Stream
- cin Keyboard से data को input करता है |
- cin ये istream class का object है |
- cin के साथ extraction operator(>>) का भी इस्तेमाल किया जाता है |
- extraction operator को एक ही line में variable के साथ अनेक extraction operators(>>) का इस्तेमाल किया जाता है |
#include <iostream.h>
using namespace std;
int main(){
int a, b;
cout << "Enter Two numbers"<<endl;
cin >>a>>b;
cout <<"Value of a : "<<a<<endl;
cout <<"Value of b : "<<b<<endl;
return 0;
}
Output :
Enter Two numbers 5 6 Value of a : 5 Value of b : 6
cerr(Console Error) : Standard Output Stream for Error
- cout और cerr ये दो Objects एक जेसे है |
- cerr ये object ostream class का है |
- cerr ये unbuffered standard output stream error है | ये तुरंत ही console पर error message को भेजता है |
#include <iostream.h>
using namespace std;
int main()
{
cerr<<"It similar to cout"<<endl;
return 0;
}
Output :
It similar to cout







No comments: