@Furry Guy
Thank you so much, I have been looking on the net for so long, nowhere did I find it as simply as you've stated. Thank you for saving me a lot of time.
@seeplus
Thank you for the note, I am just doing c++ as a university thing where our demonstrators really only care about the code working so I don't always keep best practices in mind. I will remind myself to pass by reference and use size_t instead of .size()
About lines 52 to 54, if you don't mind me asking, how are those lines no good?
I will include this explanation as the comment above it is a little bad:
the find() function with the (int) will return -1 if it cannot find the substring.
if the substring is found, it will return >=0
if we add one to the result, then we get 0 is substr is not found and >0 if found
this acts like a bool, no?
here is the comment I included in the original file for the implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
/* Commands:
@: will center text
#: will right justify text
$: will wrap and center text
*/
/* these are some instructions on how to use this namespace
this namespace is intended for display() functions that use the stringstream stuff where, we incase the text to be displayed on one set of titleBars (see example below).
you can specify what parts need to be formatted with a with the abovementioned commands
eg:
@Welcome to this program!
@written by Zane
leftJustified#rightJustified
$wrapAndCenter
leftJustified2
in the above example input we need to first calculate the len of the title bar
"~" thing and then format the console text accordingly using iomanip functions
we need to use the namespace's functions in the display functions of the classes,
so, the output (formated text) would look like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //this is a title bar, you can set the character type in the generateTitleBar()
Welcome to this program! //centered text
written by Zane //centered text
leftJustified rightJustified //right justified
wrapAndCenter //"\n" appended to the top and bottom, ie text is wrapped in "\n" and centered
leftJustified2 //left justified(no need to use namespace)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
| |