Demostrates the use of the set width manipulator
Source Code:
Result:
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream.h> #include <conio.h> #include <iomanip.h> using namespace std; int main() { int d123 = 123; float f123 = 1.23; char chA = 'A'; cout << "Demostrates the use of the set width manipulator" << endl; cout << "0...0....1....1" << endl; cout << "1...5....0....5" << endl; cout << d123 << f123 << chA << "\t | no width " <<endl; cout << setw(1) << d123 << setw(1) << f123 << setw(1) << chA << "\t | width too small" <<endl ; cout << setw(5) << d123 << setw(5) << f123 << setw(5) << chA << "\t | width 5 space to each" <<endl; getch(); return 0; }//main |
Result:
Demostrates the use of the set width manipulator" 0...0....1....1 1...5....0....5 1231.23A | no width 1231.23A | width too small 123 1.23 A | width 5 space to each
No comments:
Post a Comment