我不知道爲什麼ios::right
工作一次。完全沒有ios :: right只能工作一次C++
同樣的問題ios::hex
,ios::decimal
和其他幾個人,除非我做一些瘋狂的代碼,並讓他們奇蹟般地重新工作
#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);
for (int s = 0; s < len; s++) {
for (int c = 0; c <= s; c++) {
cout << '#';
}
cout << '\n';
}
std::cin.get();
std::cin.get();
}
預期輸出:
#
##
###
####
#####
######
我得到什麼:
#
##
###
####
#####
######
試過這個:
cout << ios::right << '#';
沒有工作。
請從這個問題中刪除'ios'標籤...每個標籤都有一個描述,它解釋了何時應該使用它,這完全是'ios'標籤的主題 – Michael
@Michael:已刪除。 –