C++ tutorial-output format


Format output in C++ programming language

C++ provides useful stream manipulators that can be used to specify the output formats. The common stream manipulators are shown below:

-left specifies left alignment.
-right specifies right alignment.
-setw sets field width of text to be outpout.
-setfill fills the remaining spaces with a specified character.
-setprecision set number of decimal places of a number to be displayed
-fixed specifies output of a number in fixed format.

Example 1:

#include<iostream>
#include<iomanip>
using namespace std;
int main(){

  cout<<right<<setw(30)<<setfill('*')<<"C++ programming"<<endl;

  system("PAUSE");
  return 0;
}

Example 2:

#include<iostream>
#include<iomanip>
using namespace std;
int main(){

  double y=123.98877777;
  cout<<setprecision(2)<<fixed<<y<<endl;

  system("PAUSE");
  return 0;
}



Comments

Tanioz comment

 Tanioz

mhh cool


2017-08-18
 Gg comment

  Gg

But output display u can show additionally..concepts clear


2017-07-24
Nish comment

 Nish

aumm useful!


2017-04-06
Anurag comment

 Anurag

very understandable


2017-03-16
Fresa Rongo comment

 Fresa Rongo

The explanation is very motivating along with the given examples. Thanks!


2017-02-21
jimmy sanz comment

 jimmy sanz

Not real clear


2016-07-20
Jacob  comment

 Jacob

i love it it is beautiful


2016-02-25
pari comment

 pari

its realy confusing


2016-02-08



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.