text alignment in C++

Most C++ beginners don't know how to align text in C++ console output. This tip will help:


-Left alignment: to align the output text left, you need to use the left keyword.
cout<<left<<setw(50)<<setfill('*')<<"C++ programming<<endl;


-Right alignment: to align the output text right, you need to use the right keyword.
cout<<right<<setw(50)<<setfill('*')<<"programming of C++"<<endl;

The setw(num_chars) function is used to set the width of the text to be output on the console window. If the length of output text is less than the width specified by the setw function, you can fill the blank spaces by any character that you like by using the setfill(character) function. You need to include iomanip header file to use the setw and setfill functions.

Posted by: Dara | post date: 10-23-2012 | Subject: C++ Programming Language




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.