Cout Statement In Dev C++
Posted By admin On 14.12.20- C++ Basics
- C++ Object Oriented
The cout object in C is an object of class ostream. It is used to display the output to the standard output device i.e. It is associated with the standard C output stream stdout. An if statement can be followed by an optional else statement, which executes when the boolean expression is false. Syntax The syntax of an if.else statement in C is −. Cout: Display Output to User Using Screen(Monitor) In C Insertion operator is used to display value to the user. The value may be some message in the form of string or variable. A C tutorial about 'If and Else Statements' The issue we have at the moment, is that in most programs we aren't always going to want to just check if something is equal to something else. Mar 09, 2020 Cout Vs Printf: Which One is Better Statement to Use in C March 9, 2020 by Helmi Uppa Leave a Comment The C language was designed and developed by Dennis Ritchie at Bell labs of American Telephone & Telegraph (aka AT&T) in 1972.
- C++ Advanced
- C++ Useful Resources
- Selected Reading
An if statement can be followed by an optional else statement, which executes when the boolean expression is false.
Syntax
The syntax of an if..else statement in C++ is −
Auto tuning near me. If the boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed.
Flow Diagram
Example
When the above code is compiled and executed, it produces the following result −
if..else if..else Statement
An if statement can be followed by an optional else if..else statement, which is very usefull to test various conditions using single if..else if statement.
When using if , else if , else statements there are few points to keep in mind.
An if can have zero or one else's and it must come after any else if's. Auto chip tuning krakow.
An if can have zero to many else if's and they must come before the else.
Once an else if succeeds, none of he remaining else if's or else's will be tested.
Syntax
The syntax of an if..else if..else statement in C++ is −
Example
When the above code is compiled and executed, it produces the following result −
- 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.No | Header 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.
Cout Statement In Dev C 2017
When the above code is compiled and executed, it produces the following result −
C++ Cout Include
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.