what is "streamsize" and "width(n)"?

O

Obnoxious User

Hello,

I read the specification of width(n) and it says this function allows
me to pad on the left to the stream's width, and this width is
"streamsize". What is streamsize exactly? Is it measured in the
number of chars or something?

It's a typedef for one of the signed basic integral types, representing
the number of characters transferred in an io operation, or the size
of io buffers.
 
J

Jess

Hello,

I read the specification of width(n) and it says this function allows
me to pad on the left to the stream's width, and this width is
"streamsize". What is streamsize exactly? Is it measured in the
number of chars or something?

Thanks,
Jess
 
J

Jess

It's a typedef for one of the signed basic integral types, representing
the number of characters transferred in an io operation, or the size
of io buffers.


I tried it on an example

cout.width(10);
cout << "hello" << endl;

Then I noticed there are only 5 characters padded on the left of
"hello". Why is it not 10?

Thanks,
Jess
 
J

John Harrison

Jess said:
I tried it on an example

cout.width(10);
cout << "hello" << endl;

Then I noticed there are only 5 characters padded on the left of
"hello". Why is it not 10?

Thanks,
Jess

Because "hello" is also five characters. width(10) means print the next
value in a 'field' of width 10, 5 spaces plus 5 for "hello" equals 10.

john
 
J

Jess

Because "hello" is also five characters. width(10) means print the next
value in a 'field' of width 10, 5 spaces plus 5 for "hello" equals 10.

john

Thanks!
Jess
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top