i have no idea why ios::right works once. totally nothing
same problem ios::hex, ios::decimal , few others unless insane codes , them magically work again
#include <iostream> #include <iomanip> using std::cout; using std::ios; int main() { int len; std::cin >> len; // w = len + 1; cout.width(len); cout.setf(ios::right); (int s = 0; s < len; s++) { (int c = 0; c <= s; c++) { cout << '#'; } cout << '\n'; } std::cin.get(); std::cin.get(); } expected output:
# ## ### #### ##### ###### what get:
# ## ### #### ##### ###### tried this:
cout << ios::right << '#'; didn't work.
you need write cout.width(len-s);cout.setf(ios::right); inside first loop because ios::right works 1 time. should
#include <iostream> #include <iomanip> using std::cout; using std::ios; int main() { int len; cin >> len; (int s = 0; s < len; s++) { cout.width(len); cout.setf(ios::right); (int c = 0; c <= s; c++) { cout<<"#"; } cout<<"\n"; } std::cin.get(); std::cin.get(); } but code not correct per required output , correct code :
#include <iostream> #include <iomanip> using std::cout; using std::ios; int main() { int len; cin >> len; (int s = 0; s < len; s++) { cout.width(len-s); // align cout.setf(ios::right); (int c = 0; c <= s; c++) { cout<<"#"; } cout<<"\n"; } std::cin.get(); std::cin.get(); }
Comments
Post a Comment