I'm having problem with my code not sure if it's a bug or there is something wrong with my code.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setfill('*') << setw(80) << "*";
cout << setw(21) << "Mt.Pleasant Official Billing Statement" << endl;
cout << setfill('*') << setw(80) << "*" << endl;
return 0;
}
Adding manual spaces works but I want to add spaces programmatically but when I tested the application this what it looks like :
setw does not move the text but sets the minimum width it should take
To achieve what you have in mind you should experiment with a bigger value since your string is longer than 21 characters, e.g.
cout << setfill('*') << setw(80) << "*" << endl;
cout << setfill(' ') << setw(56) << "Mt.Pleasant Official Billing Statement" << endl;
cout << setfill('*') << setw(80) << "*" << endl;
Output:
********************************************************************************
Mt.Pleasant Official Billing Statement
********************************************************************************
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With