GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::setw(3) C++ Standard Libary std::setw(3)

std::setw - std::setw


Defined in header <iomanip>
/*unspecified*/ setw( int n );


When used in an expression out << setw(n) or in >> setw(n), sets the width parameter
of the stream out or in to exactly n.


n - new value for width


Returns an object of unspecified type such that if str is the name of an output
stream of type std::basic_ostream<CharT, Traits> or std::basic_istream<CharT,
Traits>, then the expression str << setw(n) or str >> setw(n) behaves as if the
following code was executed:


str.width(n);


The width property of the stream will be reset to zero (meaning "unspecified") if
any of the following functions are called:


* Input


* operator>>(basic_istream&, basic_string&)
* operator>>(basic_istream&, char*)


* Output


* Overloads 1-7 of basic_ostream::operator<<() (at Stage 3 of
num_put::put())
* operator<<(basic_ostream&, char) and operator<<(basic_ostream&, char*)
* operator<<(basic_ostream&, basic_string&)
* std::put_money (inside money_put::put())
* std::quoted (when used with an output stream)


The exact effects this modifier has on the input and output vary between the
individual I/O functions and are described at each operator<< and operator>>
overload page individually.

// Run this code


#include <sstream>
#include <iostream>
#include <iomanip>


int main()
{
std::cout << "no setw: [" << 42 << "]\n"
<< "setw(6): [" << std::setw(6) << 42 << "]\n"
<< "setw(6), several elements: [" << 89 << std::setw(6) << 12 << 34 << "]\n";
std::istringstream is("hello, world");
char arr[10];
is >> std::setw(6) >> arr;
std::cout << "Input from \"" << is.str() << "\" with setw(6) gave \""
<< arr << "\"\n";
}


no setw: [42]
setw(6): [ 42]
setw(6), several elements: [89 1234]
Input from "hello, world" with setw(6) gave "hello"


width manages field width
(public member function of std::ios_base)
setfill changes the fill character
(function template)
internal sets the placement of fill characters
left (function)
right
showbase controls whether prefix is used to indicate numeric base
noshowbase (function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.