I/O
See I/O example
See File stream example.
ifstream
Open a file in read mode.
1 | ifstream file("file.txt");
|
Note
A file is closed at the end of a block.
ofstream
Open a file in write mode.
1 | ofstream file("file.txt");
|
Note
A file is closed at the end of a block.
Output format
In the descriptions below, f
is an output stream, for example cout
or a ofstream
.
All this methods, excepted the first, return a stream, so they can be chained:
1 | cout.scientific.showpos << 3 << endl;
|
precision
Set the number of digits printed to the right of the decimal point.
This applies to all subsequent floating point numbers written to that output stream.
However, this won’t make floating-point “integers” print with a decimal point.
It’s necessary to use fixed
for that effect.
1 | int np = f.precision(n)
|