Basic input/output
Standard Library अपने input/output features के माध्यम से User के साथ interaction करने के कई additional ways provide करता है। यह section कुछ most useful का short introduction प्रस्तुत करेगा।
C ++ Screen, keyboard या file जैसे sequential media में input और output perform करने के लिए stream नामक convenient abstraction का उपयोग करता है।
एक Streamएक entity है जहां एक program या तो characters को insert कर सकता है या extract कर सकता है। stream से जुड़े media या इसके किसी internal specifications के बारे में details जानने की कोई आवश्यकता नहीं है। हमें केवल यह जानने की आवश्यकता है कि stream, characters का एक source/destination हैं, और ये characters sequential रूप से provided/accepted किए जाते हैं (अर्थात,one after another)
Standard Libraries, handful stream objects को define करता है, जिसका उपयोग उन तक पहुंचने के लिए किया जा सकता है, जहां program run होता है, जहां environment द्वारा standard source और characters के destination को माना जाता है:
Stream description
- cin Standard input stream
- cout Standard output stream
- cerr Standard error (output) stream
- clog Standard logging (output) stream
हम और अधिक विस्तार से केवल cout और cin (Standard output and input stream) देखने जा रहे हैं cerr और clog भी output stream हैं, इसलिए वे essentially, cout की तरह work करते हैं, केवल अंतर यह है कि वे specific purposes के लिए stream identify करते हैं: error message और logging; जो, many cases में, most environment setups में, वे वास्तव में वही काम करते हैं: वे screen पर print करते हैं, हालांकि उन्हें individually redirected भी किया जा सकता है।
Standard output(cout) :
Mostly program environment पर, default रूप से standard output screen है, और इसे access करने के लिए defined C++ stream object cout है।
Formatted operation output के लिए, insertion operator के साथ cout का उपयोग किया जाता है, जिसे