473,394 Members | 1,800 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,394 software developers and data experts.

setfill(*) and setw() help needed!

sam142
5
i want to print like this
**************** some text with blank ********************
using setw() and setfill(*) how to to this ?
and also want to print like this
some text ***** some text
Jul 6 '12 #1

✓ answered by weaknessforcats

Consider writing a manipulator. These are functions like endl. They have a single ostream& argument and return an ostream&.

So to display five asterisks you would write:

Expand|Select|Wrap|Line Numbers
  1. ostream& FiveStars(ostream& os)
  2. {
  3.     os << "*****";
  4.     return os;
  5. }
Then to use it you code:

Expand|Select|Wrap|Line Numbers
  1. cout << FiveStars << "some text with blanks" << FiveStars << endl;
Of course, since FiveStars is a function of yours you can write code to determine what the fill character is and how many to display, etc...

1 2496
weaknessforcats
9,208 Expert Mod 8TB
Consider writing a manipulator. These are functions like endl. They have a single ostream& argument and return an ostream&.

So to display five asterisks you would write:

Expand|Select|Wrap|Line Numbers
  1. ostream& FiveStars(ostream& os)
  2. {
  3.     os << "*****";
  4.     return os;
  5. }
Then to use it you code:

Expand|Select|Wrap|Line Numbers
  1. cout << FiveStars << "some text with blanks" << FiveStars << endl;
Of course, since FiveStars is a function of yours you can write code to determine what the fill character is and how many to display, etc...
Jul 6 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matthew David Hills | last post by:
If setw() is being used to limit how many characters are pulled from a stream, should the # of characters taken from the stream depend on whether the stream is being sent to a std::string or a...
2
by: Terence | last post by:
Help Need!!! I am writing a program for a distributed system course. I need to marshall all the messages in order to send them thru a socket. The first 8 bytes of the message are used to store the...
10
by: Mathieu Malaterre | last post by:
Hello, I am trying to get rid a of sprintf in a c++ code, but I tried in several ways and couldn't figure out how to change: uint16_t group, uint16_t element; sprintf(buffer, "%04x|%04x",...
5
by: Dr. Ann Huxtable | last post by:
Hello All, I am reading a CSV (comma seperated value) file into a 2D array. I want to be able to sort multiple columns (ala Excel), so I know for starters, I cant be using the array, I need...
2
by: tvn007 | last post by:
Below is my code: #include <string> #include <iostream> #include <iomanip> int main (void){ using namespace std; string name1 = "JOHN"; int id1 = 1234;
5
by: Angel Tsankov | last post by:
Is there any way to I can make sensible use of the tab character to fill spaces in a right-justified display so that code like this using namespace std; cout << setiosflags( ios::fixed ) <<...
4
by: alternativa | last post by:
Hi, I'd like to obtain an output looking as follows: name number phone address Caroline 233 34234 White St. 12 Anna 929043 093284 Brown St. 325...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
3
by: Jess | last post by:
Hello, I'm trying to use setw and width functions to set the padding spaces between numbers. The aim is to create two white spaces between two double e.g. "1.1 1.2". I did: streamsize s =...
5
by: Christian Johannes Charbula | last post by:
hi, does anybody know how i can get the information what width for a ostream is actually set? i want to do somthing like the following, and need a way to do something like stream.getw(). ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.