how to print blank space(s) ?..

M

mark

how to print, say 50 blank spaces, or say 20 blank spaces ?

I wanted use such blank spaces that can be output in a program at
predetermined places when printing with "cout".
 
V

Victor Bazarov

mark said:
how to print, say 50 blank spaces, or say 20 blank spaces ?

I wanted use such blank spaces that can be output in a program at
predetermined places when printing with "cout".

Use a loop

for (int i = 0; i < 50; ...

and output one space at a time

Or, declare a constant string consisting of 50 spaces and
output it.

Or, declare a constant string consisting of 5 spaces and
output it in a loop that executes 10 times.

Or, declare a constant string consisting of 10 spaces and
output it in a loop that executes 5 times.

Or, ...

Victor
 
O

Owen Jacobson

how to print, say 50 blank spaces, or say 20 blank spaces ?

I wanted use such blank spaces that can be output in a program at
predetermined places when printing with "cout".

What are you really trying to accomplish? If you want aligned output,
look into the setw family of operations on ostreams. If you really want
to output any value more than once, loop.
 
J

Jacob

Use a loop

for (int i = 0; i < 50; ...

and output one space at a time

Or, declare a constant string consisting of 50 spaces and
output it.

Or, declare a constant string consisting of 5 spaces and
output it in a loop that executes 10 times.

Or, declare a constant string consisting of 10 spaces and
output it in a loop that executes 5 times.

Or, ...

Victor

int main(void){
int increment;

for(increment = 1; increment <= 50; increment++){
if(!(50 % increment)){
printf("Or, declare a constant string \
consisting of %i spaces and\noutput it in a loop that executes %i \
times.\n\n", increment, 50 / increment);
}
}
return 0;
}

/***
Yes, yes this is a joke.
***/
 
D

David Harmon

On 16 Jun 2004 18:56:39 -0700 in comp.lang.c++, (e-mail address removed) (mark) wrote,
how to print, say 50 blank spaces, or say 20 blank spaces ?

cout << setw(50) << " ";
 
M

Mike Wahler

mark said:
how to print, say 50 blank spaces, or say 20 blank spaces ?

std::cout << std::string(50, ' ');

std::cout << std::string(20, ' ');
I wanted use such blank spaces that can be output in a program at
predetermined places when printing with "cout".

The only way you can 'predetermine' where the output goes
is to keep track of how many characters you've printed
so far on each line. There is no way to specify a
vertical position to print on a video device. I/O in
C++ is only in terms of 'streams of characters'.


-Mike
 

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
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top