ios output width
Hi,
I'd like to use copy() to send the content of an integer container to
cout. How can I make sure that /all/ of them are printed with width 2?
#include <iostream>
#include <iterator>
int v[]={42,3,42};
using namespace std;
int main(){
cout.width(2);
copy(v,v+3,ostream_iterator<int>(cout," "));
cout<<endl;
return 0;
}
gives
42 3 42
I'd like it to be
42 3 42
instead. I read in Stroustrup that width() only applies to the next
output. I thought using format flags with setf would be the way to do it
like when I want to output the integers in say octal. But there are no
format "flags" for width. What can I do?
Ralf
|