Hi all, I have to display final result of my program in a centre and with a box around it. to Do that I was given notes on <iomanip>. I am complitely new to c++ and I never actually used iomanip, so this is what I came up with:
Well, setting fill character back to space will work. You can get previous fill character this way:
1 2 3
char fill_char = std::cout.fill('-');
//set fill character to dash and store previous one in fill_char variable
//You can use it to restore fill character later
Additionally if you need to cancel more than one manipulator, you can save stream format state and then restore it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <iomanip>
int main()
{
//Create and save state
std::ios state(nullptr);
state.copyfmt(std::cout);
std::cout << std::setfill('-') << std::setw(20) << 'a' << '\n';
//Restore state
std::cout.copyfmt(state);
std::cout << std::setw(20) << 'a' << '\n';
}
my name is not in the centre and to be honest the whole box is a bit off as well. I didn't use the stream format state 'cos I don't fully understand it. I might try it later when i get my box and all centralized.
Any suggestions welcome..