*To format data we can use escape sequences*.
The most common ones are: \n
- newline & \t
- tab
We can also format the output by using the iomanip
library.
Include it as #include .
Once it is included, we can format output using the iomanip
library.
For example, we can set the width of an output using the setw
command.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
cout << "\n\nThe text without any formatting.\n";
cout << "Ints" << "Floats" << "Doubles" << "\n";
cout << "\nThe text with setw(15)\n";
cout << "Ints" << setw(15) << "Floats" << setw(15) << "Doubles" << "\n";
cout << "\n\nThe text with tabs\n";
cout << "Ints\t" << "Floats\t" << "Doubles" << "\n";
return 0;
}
Output will be:
The text without any formating
IntsFloatsDoubles
The text with setw(15)
Ints Floats Doubles
The text with tabs
IntsFloatsDoubles