setw

setw - cout << setw(20)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//Example: setw #include <iostream> #include <iomanip> #include < string> using namespace std; int main() { int x = 19, a = 345, N=12; i double y = 76.384, z = 0.0000007658; d string temp = "hello"; s cout << endl << "Default format \n" ; cout<<a<<'\n'<<"Hi"<<" \n"<<x<<y<< '\n'<<temp <<'\n'<<z<<'\n'<<endl; c cout<<fixed<<showpoint; cout <<endl <<"fixed format for z = "<<z << endl; cout<<setprecision(2); c cout <<"setprecision(2), fixed<<showpoint Left" << endl<<endl ; cout<<"12345678901234567890"<<endl; c cout << left ; cout<<setw(5)<<x<<endl; c cout<<setw(2)<< z <<endl ; cout<<setw(5)<<a<<setw(5)<<"Hi"<<setw(5)<<x<<setw(5)<< z <<endl<<endl; c cout << setw(20) << temp ; cout << "\n Right " << endl ; c cout <<"setprecision(3), fixed<<showpoint Right" << endl<<endl ; cout << right ; cout<<setprecision(3); c cout<<setw(6)<<a<<setw(6)<<y <<setw(6)<<x<<setw(6)<< z<<endl; c cout<<setw(6)<<x<<setw(6)<<a<<setw(6)<<y<<setw(6)<< z<<endl<<endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout &lt;&lt; setw(20) &lt;&lt; temp ; c cout&lt;&lt;setw(5)&lt;&lt;a&lt;&lt;x&lt;&lt;endl; c cout&lt;&lt;setw(2)&lt;&lt;a&lt;&lt;setw(4)&lt;&lt;x&lt;&lt;setw(5)&lt;&lt; z&lt;&lt;endl; c cout&lt;&lt;fixed&lt;&lt;showpoint&lt;&lt;setprecision(7); c cout&lt;&lt;setw(2)&lt;&lt; z &lt;&lt;endl&lt;&lt;left ; cout &lt;&lt; setw(N) &lt;&lt; &quot;x is : &quot;&lt;&lt; right &lt;&lt;setw(N-2) &lt;&lt;x &lt;&lt;endl ; cout &lt;&lt; left &lt;&lt; setw(N) &lt;&lt; &quot;z = : &quot;&lt;&lt; right &lt;&lt; setw(N-2)&lt;&lt; z &lt;&lt;endl ; cout &lt;&lt; setw(N) &lt;&lt; &quot;Y : &quot;&lt;&lt; setw(N-2)&lt;&lt; y &lt;&lt;endl ; cout &lt;&lt; setw(N) &lt;&lt; &quot;A as int: &quot;&lt;&lt; setw(N-2)&lt;&lt; a &lt;&lt;endl ; c return 0; } /*output / Default format 345 Hi 1976.384 hello 7.658e-007 7 fixed format for z = 0.000001 setprecision(2), fixed&lt;&lt;showpoint Left s 12345678901234567890 19 0.00 345 Hi 19 0.00 3 hello Right setprecision(3), fixed&lt;&lt;showpoint Right s 34576.384 19 0.000 19 34576.384 0.000 hello 34519 345 190.000 0.0000008 x is : 19 z = : 0.0000008 Y : 76.3840000 A as int: 345 */...
View Full Document

Page1 / 2

setw - cout &amp;amp;lt;&amp;amp;lt; setw(20)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online