-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_manipulator.cpp
55 lines (44 loc) · 1020 Bytes
/
stream_manipulator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
void floatingPointPrecision(){
double root = sqrt(2.0);
int places; //0-9
cout<<fixed;
for(places=0; places<=9; ++places){
cout.precision(places);
cout<<root<<endl;
}
for(places=0; places<=9; ++places){
cout<<setprecision(places);
cout<<root<<endl;
}
}
void fieldWidth(){
int x = 10000;
cout<<x<<endl;
cout<<showbase<<setw(10)<<x<<endl;
cout<<left<<setw(10)<<x<<endl;
cout<<right<<setw(10)<<x<<endl;//By default
cout<<internal<<setw(10)<<hex<<x<<endl;
cout<<left;
cout.fill('*');
cout<<setw(10)<<dec<<x<<endl;
cout<<left<<setw(10)<<setfill('%')<<x<<endl;
cout<<internal<<setw(10)<<setfill('^')<<hex<<x<<endl;
int widthValue=4;
char sentence[10];
cout<<"Enter a sentence"<<endl;
cin.width(5);
cout.fill('*');
while(cin>>sentence){
cout.width(widthValue++);
cout<<sentence<<endl;
cin.width(5);
}
}
int main(){
floatingPointPrecision();
//fieldWidth();
}