473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

printout of characters

Hiya

Can anybody remind me of the format command, or otherwise, to print a number
of the same character e.g. if I wanted to printout 20 *'s

********************
then I'm sure there is an inbuilt command, without using a loop, that will
do it.

Can anybody remind me of what it is?

Ta

Geoff
Jul 22 '05 #1
2 1019

"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
Hiya

Can anybody remind me of the format command,
C++ does not have 'commands'.
or otherwise, to print a number
of the same character e.g. if I wanted to printout 20 *'s

********************
then I'm sure there is an inbuilt command, without using a loop, that will
do it.

Can anybody remind me of what it is?


There are a virtually unlimited number of possible ways.
I'd do it like this:

#include <iostream>
#include <string>

int main()
{
const std::string::size_type count(20);
char c('*');

std::cout << std::string(count, c) << '\n';
return 0;
}

-Mike
Jul 22 '05 #2
> Can anybody remind me of the format command, or otherwise, to print a
number
of the same character e.g. if I wanted to printout 20 *'s ********************


There are quite a few possibilities. One reasonably clean one would be:

std::fill_n(std::ostream_iterator<char>(std::cout) , 20, '*');

If you prefer to use only the native abilities of iostreams, you could
use:

std::cout << std::setfill('*') << std::setw(20) << ' ';

but this prints an extra space at the end of the line -- if that's all
that's going to go on the line, you might prefer:

std::cout << std::setfill('*') << std::setw(20) << '\n';

or, if you don't want a new line, something like:

std::cout << std::setfill('*') << std::setw(19) << '*';

At least in theory, the versions using iostreams capabilities might be
marginally more efficient, but given that this is producing output on a
stream, it's hard to imagine how it would make any real difference, so
at least to me, fill_n seems the obvious choice.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: RC | last post by:
I am using docmd.printout to send Reports (formatted as labels) to a barcode label printer. I need to collate the labels so that I print lable 1 twice, then label 2 twice, then label 3 twice, etc....
2
by: Smartin | last post by:
Question about DoCmd.PrintOut in A97. I have a form on which all the controls are unbound. There is a large textbox that the user can type stuff in and a couple labels. I am trying to code a...
1
by: Elhanan | last post by:
hi.. sorry for the cross posting, i'm simply not sure where this goes (i'm still genrating this from an asp page). i'm trying to printout normal text from IE using Generic Text Driver like...
1
by: =?Utf-8?B?S2ltIFM=?= | last post by:
I have a word document I only want to printout ( not save as file ) and I use Word printout method in backgrund but my XP operativ i so slow that a "dummy" dociment also get stored. which...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.