description | title | ms.date | f1_keywords | ms.assetid | helpviewer_keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: <ios> functions |
<ios> functions |
11/04/2016 |
|
1382d53f-e531-4b41-adf6-6a1543512e51 |
|
Specifies that variables of type bool appear as true
or false
in the stream.
ios_base& boolalpha(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, variables of type bool
are displayed as 1 or 0.
boolalpha
effectively calls str.
setf( ios_base::boolalpha
), and then returns str.
noboolalpha reverses the effect of boolalpha
.
// ios_boolalpha.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
bool b = true;
cout << b << endl;
boolalpha( cout );
cout << b << endl;
noboolalpha( cout );
cout << b << endl;
cout << boolalpha << b << endl;
}
1
true
1
true
Specifies that integer variables appear in base 10 notation.
ios_base& dec(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, integer variables are displayed in base 10.
dec
effectively calls str.
setf( ios_base::dec
, ios_base::basefield
), and then returns str.
// ios_dec.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
int i = 100;
cout << i << endl; // Default is base 10
cout << hex << i << endl;
dec( cout );
cout << i << endl;
oct( cout );
cout << i << endl;
cout << dec << i << endl;
}
100
64
100
144
100
Configures the flags of an ios_base
object to use a default display format for float values.
ios_base& defaultfloat(ios_base& iosbase);
_Iosbase
An ios_base
object.
The manipulator effectively calls iosbase.
ios_base::unsetf(ios_base::floatfield)
, then returns iosbase.
Specifies that a floating-point number is displayed in fixed-decimal notation.
ios_base& fixed(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
fixed
is the default display notation for floating-point numbers. scientific causes floating-point numbers to be displayed using scientific notation.
The manipulator effectively calls str.setf( ios_base::fixed
, ios_base::floatfield
), and then returns str.
// ios_fixed.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
float i = 1.1F;
cout << i << endl; // fixed is the default
cout << scientific << i << endl;
cout.precision( 1 );
cout << fixed << i << endl;
}
1.1
1.100000e+000
1.1
Specifies that integer variables shall appear in base 16 notation.
ios_base& hex(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, integer variables are displayed in base 10 notation. dec and oct also change the way integer variables appear.
The manipulator effectively calls str
.setf( ios_base::hex
, ios_base::basefield
), and then returns str.
See dec for an example of how to use hex
.
ios_base& hexfloat (ios_base& str);
enum class io_errc {
stream = 1
};
Causes a number's sign to be left justified and the number to be right justified.
ios_base& internal(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
showpos causes the sign to display for positive numbers.
The manipulator effectively calls str.
setf(
ios_base::internal,
ios_base::adjustfield)
, and then returns str.
// ios_internal.cpp
// compile with: /EHsc
#include <iostream>
#include <iomanip>
int main( void )
{
using namespace std;
float i = -123.456F;
cout.fill( '.' );
cout << setw( 10 ) << i << endl;
cout << setw( 10 ) << internal << i << endl;
}
..-123.456
-..123.456
template <> struct is_error_code_enum<io_errc> : public true_type { };
const error_category& iostream_category() noexcept;
Causes text that is not as wide as the output width to appear in the stream flush with the left margin.
ios_base& left(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
The manipulator effectively calls str.
setf(ios_base::left, ios_base::adjustfield)
, and then returns str.
// ios_left.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
double f1= 5.00;
cout.width( 20 );
cout << f1 << endl;
cout << left << f1 << endl;
}
5
5
error_code make_error_code(io_errc e) noexcept;
error_condition make_error_condition(io_errc e) noexcept;
Specifies that variables of type bool appear as 1 or 0 in the stream.
ios_base& noboolalpha(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, noboolalpha
is in effect.
noboolalpha
effectively calls str.
unsetf(ios_base::boolalpha)
, and then returns str.
boolalpha reverses the effect of noboolalpha
.
See boolalpha for an example of using noboolalpha
.
Turns off indicating the notational base in which a number is displayed.
ios_base& noshowbase(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
noshowbase
is on by default. Use showbase to indicate the notational base of numbers.
The manipulator effectively calls str.
unsetf(ios_base::showbase)
, and then returns str.
See showbase for an example of how to use noshowbase
.
Displays only the whole-number part of floating-point numbers whose fractional part is zero.
ios_base& noshowpoint(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
noshowpoint
is on by default; use showpoint and precision to display zeros after the decimal point.
The manipulator effectively calls str.
unsetf(ios_base::showpoint)
, and then returns str.
// ios_noshowpoint.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
double f1= 5.000;
cout << f1 << endl; // noshowpoint is default
cout.precision( 4 );
cout << showpoint << f1 << endl;
cout << noshowpoint << f1 << endl;
}
5
5.000
5
Causes positive numbers to not be explicitly signed.
ios_base& noshowpos(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
noshowpos
is on by default.
The manipulator effectively calls str.
unsetf(ios_base::showpos)
, then returns str.
See showpos for an example of using noshowpos
.
Cause spaces to be read by the input stream.
ios_base& noskipws(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, skipws is in effect. When a space is read in the input stream, it signals the end of the buffer.
The manipulator effectively calls str.
unsetf(ios_base::skipws)
, and then returns str.
// ios_noskipws.cpp
// compile with: /EHsc
#include <iostream>
#include <string>
int main() {
using namespace std;
string s1, s2, s3;
cout << "Enter three strings: ";
cin >> noskipws >> s1 >> s2 >> s3;
cout << "." << s1 << "." << endl;
cout << "." << s2 << "." << endl;
cout << "." << s3 << "." << endl;
}
Causes output to be buffered and processed on when the buffer is full.
ios_base& nounitbuf(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
unitbuf causes the buffer to be processed when it is not empty.
The manipulator effectively calls str.
unsetf(ios_base::unitbuf)
, and then returns str.
Specifies that hexadecimal digits and the exponent in scientific notation appear in lowercase.
ios_base& nouppercase(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
The manipulator effectively calls str.
unsetf(ios_base::uppercase)
, and then returns str.
See uppercase for an example of using nouppercase
.
Specifies that integer variables appear in base 8 notation.
ios_base& oct(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, integer variables are displayed in base 10 notation. dec and hex also change the way integer variables appear.
The manipulator effectively calls str.
setf(ios_base::oct, ios_base::basefield)
, and then returns str.
See dec for an example of how to use oct
.
Causes text that is not as wide as the output width to appear in the stream flush with the right margin.
ios_base& right(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
left also modifies the justification of text.
The manipulator effectively calls str.
setf(ios_base::right, ios_base::adjustfield)
, and then returns str.
// ios_right.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
double f1= 5.00;
cout << f1 << endl;
cout.width( 20 );
cout << f1 << endl;
cout.width( 20 );
cout << left << f1 << endl;
cout.width( 20 );
cout << f1 << endl;
cout.width( 20 );
cout << right << f1 << endl;
cout.width( 20 );
cout << f1 << endl;
}
5
5
5
5
5
5
Causes floating-point numbers to be displayed using scientific notation.
ios_base& scientific(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, fixed notation is in effect for floating-point numbers.
The manipulator effectively calls str.
setf(ios_base::scientific, ios_base::floatfield)
, and then returns str.
// ios_scientific.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
float i = 100.23F;
cout << i << endl;
cout << scientific << i << endl;
}
100.23
1.002300e+002
Indicates the notational base in which a number is displayed.
ios_base& showbase(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
The notational base of a number can be changed with dec, oct, or hex.
The manipulator effectively calls str.
setf(ios_base::showbase)
, and then returns str.
// ios_showbase.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
int j = 100;
cout << showbase << j << endl; // dec is default
cout << hex << j << showbase << endl;
cout << oct << j << showbase << endl;
cout << dec << j << noshowbase << endl;
cout << hex << j << noshowbase << endl;
cout << oct << j << noshowbase << endl;
}
100
0x64
0144
100
64
144
Displays the whole-number part of a floating-point number and digits to the right of the decimal point even when the fractional part is zero.
ios_base& showpoint(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, noshowpoint is in effect.
The manipulator effectively calls str.
setf(ios_base::showpoint)
, and then returns str.
See noshowpoint for an example of using showpoint
.
Causes positive numbers to be explicitly signed.
ios_base& showpos(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
noshowpos is the default.
The manipulator effectively calls str.
setf(ios_base::showpos)
, and then returns str.
// ios_showpos.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
int i = 1;
cout << noshowpos << i << endl; // noshowpos is default
cout << showpos << i << endl;
}
1
+1
Cause spaces to not be read by the input stream.
ios_base& skipws(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, skipws
is in effect. noskipws will cause spaces to be read from the input stream.
The manipulator effectively calls str.
setf(ios_base::skipws)
, and then returns str.
#include <iostream>
#include <string>
int main( )
{
using namespace std;
char s1, s2, s3;
cout << "Enter three characters: ";
cin >> skipws >> s1 >> s2 >> s3;
cout << "." << s1 << "." << endl;
cout << "." << s2 << "." << endl;
cout << "." << s3 << "." << endl;
}
1 2 3
Enter three characters: 1 2 3
.1.
.2.
.3.
Causes output to be processed when the buffer is not empty.
ios_base& unitbuf(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
Note that endl
also flushes the buffer.
nounitbuf is in effect by default.
The manipulator effectively calls str.
setf(
ios_base::unitbuf)
, and then returns str.
Specifies that hexadecimal digits and the exponent in scientific notation appear in uppercase.
ios_base& uppercase(ios_base& str);
str
A reference to an object of type ios_base, or to a type that inherits from ios_base
.
A reference to the object from which str is derived.
By default, nouppercase is in effect.
The manipulator effectively calls str.
setf(
ios_base::uppercase)
, and then returns str.
// ios_uppercase.cpp
// compile with: /EHsc
#include <iostream>
int main( void )
{
using namespace std;
double i = 1.23e100;
cout << i << endl;
cout << uppercase << i << endl;
int j = 10;
cout << hex << nouppercase << j << endl;
cout << hex << uppercase << j << endl;
}
1.23e+100
1.23E+100
a
A