The C language does not include an I/O system, but one of its core concepts is that it is extendible. Although its operator set cannot be increased, the meanings of operators depend on the context in which they are used. When applied to new objects the meaning can be redefined. This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. Feb 09, 2015 This feature is not available right now. Please try again later. Jun 27, 2010  A project file keeps the build settings with the project rather than simply using whatever you may have configured Dev-C to use at that time. Moreover the New Project dialog provides a number of project templates to get you started with the correct settings and example code, and also allows you to set the default language for the project, which would have solved your problem in this case.

  • C++ Basics
  • C++ Object Oriented
  • C++ Advanced
  • C++ Useful Resources
  • Selected Reading

The C++ standard libraries provide an extensive set of input/output capabilities which we will see in subsequent chapters. This chapter will discuss very basic and most common I/O operations required for C++ programming.

C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device like a keyboard, a disk drive, or a network connection etc. to main memory, this is called input operation and if bytes flow from main memory to a device like a display screen, a printer, a disk drive, or a network connection, etc., this is called output operation.

I/O Library Header Files

There are following header files important to C++ programs −

Sr.NoHeader File & Function and Description
1

<iostream>

This file defines the cin, cout, cerr and clog objects, which correspond to the standard input stream, the standard output stream, the un-buffered standard error stream and the buffered standard error stream, respectively.

2

<iomanip>

This file declares services useful for performing formatted I/O with so-called parameterized stream manipulators, such as setw and setprecision.

3

<fstream>

This file declares services for user-controlled file processing. We will discuss about it in detail in File and Stream related chapter.

The Standard Output Stream (cout)

The predefined object cout is an instance of ostream class. The cout object is said to be 'connected to' the standard output device, which usually is the display screen. The cout is used in conjunction with the stream insertion operator, which is written as << which are two less than signs as shown in the following example.

When the above code is compiled and executed, it produces the following result −

The C++ compiler also determines the data type of variable to be output and selects the appropriate stream insertion operator to display the value. The << operator is overloaded to output data items of built-in types integer, float, double, strings and pointer values.

The insertion operator << may be used more than once in a single statement as shown above and endl is used to add a new-line at the end of the line.

The Standard Input Stream (cin)

The predefined object cin is an instance of istream class. The cin object is said to be attached to the standard input device, which usually is the keyboard. The cin is used in conjunction with the stream extraction operator, which is written as >> which are two greater than signs as shown in the following example.

When the above code is compiled and executed, it will prompt you to enter a name. You enter a value and then hit enter to see the following result −

The C++ compiler also determines the data type of the entered value and selects the appropriate stream extraction operator to extract the value and store it in the given variables.

The stream extraction operator >> may be used more than once in a single statement. To request more than one datum you can use the following −

This will be equivalent to the following two statements −

The Standard Error Stream (cerr)

The predefined object cerr is an instance of ostream class. The cerr object is said to be attached to the standard error device, which is also a display screen but the object cerr is un-buffered and each stream insertion to cerr causes its output to appear immediately.

The cerr is also used in conjunction with the stream insertion operator as shown in the following example.

When the above code is compiled and executed, it produces the following result −

The Standard Log Stream (clog)

The predefined object clog is an instance of ostream class. The clog object is said to be attached to the standard error device, which is also a display screen but the object clog is buffered. This means that each insertion to clog could cause its output to be held in a buffer until the buffer is filled or until the buffer is flushed.

The clog is also used in conjunction with the stream insertion operator as shown in the following example.

When the above code is compiled and executed, it produces the following result −

You would not be able to see any difference in cout, cerr and clog with these small examples, but while writing and executing big programs the difference becomes obvious. So it is good practice to display error messages using cerr stream and while displaying other log messages then clog should be used.

-->

Declares objects that control reading from and writing to the standard streams. This include is often the only header you need to do input and output from a C++ program.

Syntax

Note

Header File For Cout In Dev C++

The <iostream> library uses the #include <ios>, #include <streambuf>, #include <istream>, and #include <ostream> statements.

Remarks

The objects fall into two groups:

  • cin, cout, cerr, and clog are byte oriented, doing conventional byte-at-a-time transfers.

  • wcin, wcout, wcerr, and wclog are wide oriented, translating to and from the wide characters that the program manipulates internally.

Once you do certain operations on a stream, such as the standard input, you can't do operations of a different orientation on the same stream. Therefore, a program can't operate interchangeably on both cin and wcin, for example.

All the objects declared in this header share a peculiar property — you can assume they're constructed before any static objects you define, in a translation unit that includes <iostream>. Equally, you can assume that these objects aren't destroyed before the destructors for any such static objects you define. (The output streams are, however, flushed during program termination.) Therefore, you can safely read from or write to the standard streams before program startup and after program termination.

This guarantee isn't universal, however. A static constructor may call a function in another translation unit. The called function can't assume that the objects declared in this header have been constructed, given the uncertain order in which translation units participate in static construction. To use these objects in such a context, you must first construct an object of class ios_base::Init.

Global Stream Objects

Cout In Dev Cpp

cerrSpecifies the cerr global stream.
cinSpecifies the cin global stream.
clogSpecifies the clog global stream.
coutSpecifies the cout global stream.
wcerrSpecifies the wcerr global stream.
wcinSpecifies the wcin global stream.
wclogSpecifies the wclog global stream.
wcoutSpecifies the wcout global stream.

cerr

The object cerr controls output to a stream buffer associated with the object stderr, declared in <cstdio>.

Return Value

An ostream object.

Remarks

The object controls unbuffered insertions to the standard error output as a byte stream. Once the object is constructed, the expression cerr.flags&unitbuf is nonzero, and cerr.tie() &cout.

Example

cin

Specifies the cin global stream.

Return Value

An istream object.

Remarks

The object controls extractions from the standard input as a byte stream. Once the object is constructed, the call cin.tie returns &cout.

Example

In this example, cin sets the fail bit on the stream when it comes across non-numeric characters. The program clears the fail bit and strips the invalid character from the stream to continue.

clog

Specifies the clog global stream.

Return Value

C++ Cout Example

An ostream object.

Remarks

The object controls buffered insertions to the standard error output as a byte stream.

Cout C Programming

Example

See cerr for an example of using clog.

cout

Specifies the cout global stream.

Return Value

An ostream object.

Remarks

The object controls insertions to the standard output as a byte stream.

Example

See cerr for an example of using cout.

wcerr

Specifies the wcerr global stream.

Return Value

A wostream object.

Remarks

The object controls unbuffered insertions to the standard error output as a wide stream. Once the object is constructed, the expression wcerr.flags&unitbuf is nonzero.

Example

See cerr for an example of using wcerr.

wcin

Specifies the wcin global stream.

Return Value

A wistream object.

Remarks

The object controls extractions from the standard input as a wide stream. Once the object is constructed, the call wcin.tie returns &wcout.

Example

/c-game-state-game-dev-visual-studio.html. See cerr for an example of using wcin.

wclog

Specifies the wclog global stream.

Return Value

A wostream object.

Remarks

The object controls buffered insertions to the standard error output as a wide stream.

Example

See cerr for an example of using wclog.

wcout

Specifies the wcout global stream.

Return Value

A wostream object.

Remarks

Waves vst plugins download. The object controls insertions to the standard output as a wide stream.

Example

See cerr for an example of using wcout.

CString instances in a wcout statement must be cast to const wchar_t*, as shown in the following example.

How To Declare Cout In Dev C++

For more information, see Basic CString Operations.

See also

Header Files Reference
Thread Safety in the C++ Standard Library
iostream Programming
iostreams Conventions