Iostream

Iostream

iostream is a header file which is used for input/output in the C++ programming language. It is part of the C++ standard library. The name stands for Input/Output Stream. In C++ and its predecessor, the C programming language, there is no special syntax for streaming data input or output. Instead, these are combined as a library of functions. Like the cstdio header inherited from C's stdio.h, iostream provides basic input and output services for C++ programs. iostream uses the objects cin, cout, cerr, and clog for sending data to and from the standard streams input, output, error (unbuffered), and error (buffered) respectively. As part of the C++ standard library, these objects are a part of the std namespace.

The canonical Hello world program can be expressed as follows:
#include

int main(){ std::cout << "Hello, world! "; return 0;}This program would output "Hello, world!" followed by a newline.

The cout object is of type ostream, which overloads the left bit-shift operator to make it perform an operation completely unrelated to bitwise operations. The cerr and clog objects are also of type ostream, so they overload that operator as well. The cin object is of type istream, which overloads the right bit-shift operator. The directions of the bit-shift operators make it seem as though data is flowing towards the output stream or flowing away from the input stream.

A commonly-used alternative to the newline character is endl, which is used as follows:


#include

int main(){ std::cout << "Hello, world!" << std::endl; return 0;}

endl is an output manipulator that writes a newline and flushes the buffer, ensuring that the data is output immediately. Several other manipulators are listed below.

Output formatting

Methods

Example:cout.width(10);cout << "ten" << "four" << "four";

Manipulators

Manipulators are objects that can modify a stream using the << or >> operators.

Other manipulators can be found using the header iomanip.

Criticism

In some environments, such as MinGW and embedded systems, the C++ standard library must be statically linked to a program, either because of licensing issues [ [http://www.mingw.org/mingwfaq.shtml#faq-cpp-size MinGW Frequently Asked Questions: Why is my C++ binary so large?] ] or because of the lack of a C++ library in the system's firmware.Some implementations of the C++ standard library, such as GNU libstdc++, automatically construct a locale when building an ostream even if no types that could be affected by a locale (such as date, time, and money) are ever used. [GNU libstdc++ source code, bits/ios_base.h] For instance, a statically-linked hello world program with the GNU implementation of the C++ standard library produces an executable an order of magnitude larger than an equivalent program that uses &lt;cstdio&gt;. [http://pineight.com/rant/#cbloatbloat Pin Eight: RAnT (Rants, Articles, and Treatises) ] ] There exist partial implementations of the C++ standard library designed for space-constrained environments; their &lt;iostream&gt; may leave out features that programs in such environments may not need, such as locale support. [ [http://cxx.uclibc.org/ uClibc++ C++ library] ]

References

External links

* [http://incubator.apache.org/stdcxx/doc/stdlibug/VIII.html Apache C++ Standard Library Iostreams]
* [http://www.informit.com/articles/article.aspx?p=170770 Comprehensive tutorial on formatting output in C++.]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Iostream — es un archivo de cabecera que es utilizado para operaciones de entrada/salida en el lenguaje de programación C++. iostream es parte de la biblioteca estándar de C++. Su nombre es un acrónimo de Input/Output Stream. El flujo de entrada y salida de …   Wikipedia Español

  • Iostream — iostream  заголовочный файл с классами, функциями и переменными для организации ввода вывода в языке программирования C++. Он включён в стандартную библиотеку C++. Название образовано от Input/Output Stream («поток ввода вывода»). В языке… …   Википедия

  • iostream — Стандартная библиотека языка программирования C++ fstream iomanip ios iostream sstream Стандартная библиотека шаблонов …   Википедия

  • iostream — C++ Standard Library fstream iomanip ios iostream sstream string …   Wikipedia

  • Iostream.h — …   Википедия

  • Iostream.hpp — …   Википедия

  • C++ — Desarrollador(es) Bjarne Stroustrup, Bell Labs Información general …   Wikipedia Español

  • C++ — У этого термина существуют и другие значения, см. C. См. также: Си (язык программирования) C++ Семантика: мультипарадигмальный: объектно ориентированное, обобщённое, процедурное, метапрограммирование Тип исполнения: компилируемый Появился в …   Википедия

  • Стандартная библиотека языка C++ — Стандартная библиотека языка программирования C++ fstream iomanip ios iostream sstream Стандартная библиотека шаблонов …   Википедия

  • Printf — The class of printf functions (which stands for print formatted ) is a class of functions, typically associated with curly bracket programming languages, that accept a string parameter (called the format string) which specifies a method for… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”