iomanip - STL C++

setw()

Declaration

(unspecified) setw(int iWidth);

Description

This is the setw() function for output stream manipulation. The argument iWidth sets the number of characters that are used for numerical output.

Header Include

#include <iomanip>

Example

#include <iostream>
#include <iomanip>

int main() {
	using namespace std;

	double dPi = 3.14159;
	// Output the value with default settings
	cout << "Default : " << dPi << endl;

	// Output the value using 10 width
	cout << "Width 10: " << setw(10) << dPi << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

setw() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.