Formatted Input and Output

Formatted Input and Output - More detailed input and output...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: More detailed input and output Dr. David Gaitros Reference: Starting out with C++, From Control Structures through Objects Formatted Output using setw() cout allows just enough spaces to print values. Print out the number 25 (cout<< 25; ) and only two spaces will be set aside Print out the number 1000 (cout << 100) and three spaces will be set aside Use the set width setw() to specify the area to display the data. Specifies the minimum area in which the data is to be printed out. If the value is too large to fit in the area, cout will only use the spaces necessary to print out the value. #include <iostream> #include <iomanip> using namespace std; // Note the need for iomanip // library. This is not // specified in the book. int main9void) { int number=23; cout << number <<endl; cout << setw(10)<< number<<endl; return 0; } /* This is what the output looks like the first value printed in just two spaces, the second right justified in 10 23 23 */ #include <iostream>...
View Full Document

Page1 / 11

Formatted Input and Output - More detailed input and output...

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

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