×

C++ Programs

C++ Most popular & Searched Programs

C++ Basic I/O Programs

C++ Constructor & Destructor Programs

C++ Manipulators Programs

C++ Inheritance Programs

C++ Operator Overloading Programs

C++ File Handling Programs

C++ Bit Manipulation Programs

C++ Classes & Object Programs

C++ program to demonstrate example of setw manipulator

Learn about the setw manipulator in C++, and demonstrate the use of setw manipulator using C++ program.
[Last updated : March 02, 2023]

setw Manipulator in C++

The 'setw' stands for set width. Furthermore, its is used to set the ios library field width or specifies the minimum number of character positions a variable will consume.

This program will demonstrate example of setw manipulator in c++ programming language.

setw manipulator program in C++

/*C++ program to demonstrate example of setw manipulator.*/
 
#include <iostream>
#include <iomanip>
using namespace std;
 
int main()
{
    char pName[3][30]={"Dove Soap","Colgate","Vim"};
    int  qty[3]  ={5,10,15};
    int  i;
     
    cout << setw(30) << "Product Name" << setw(20) << "Quantity" << endl;
    for(i=0; i< 3; i++){
        cout << setw(30) << pName[i] << setw(20) << qty[i] << endl;
    }
    return 0;
}

Output

                  Product Name            Quantity
                     Dove Soap                   5
                       Colgate                  10
                           Vim                  15

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.